M
M
Meehalkoff2016-03-10 21:29:42
Android
Meehalkoff, 2016-03-10 21:29:42

Why does SimpleCursorAdapter have this behavior?

There is such a code.

public void refreshTransactions(){
        Cursor cursor = dbHelper.getAllTransactions(db);

        String[] from = new String[] {"a.name","c.name","t.date", "t.amount"};
        int[] to = new int[] { R.id.tvAccount, R.id.tvCategory, R.id.tvDate, R.id.tvAmount };

        SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this,R.layout.item_journal_transaction,
                cursor,from,to,0);
        ListView listView = (ListView)findViewById(R.id.list_JournalTransaction);
        listView.setAdapter(cursorAdapter);
}

//из dbHelper
public Cursor getAllTransactions(SQLiteDatabase db) {
        return  db.query(TableNames.VIEW_TRANSACTIONS,
                null,null,null,null,null,null);
}

//строка создающая представление 
String VIEW_TRANSACTIONS = "" +
            "create view \n" +
            TableNames.VIEW_TRANSACTIONS+" "+
            "as select t._id, t.date,a.name,c.name, t.amount\n" +
            "from accounts a, categorys c, transactions t\n" +
            "where t.categorys_id = c._id\n" +
            "and t.accounts_id = a._id;";

8ebb68599c50478a9e3bd59fe362725e.png
It can be seen that the view works fine.
a0a9a95213d34b2fa7ee8671f707aaf0.png
But in ListView, the adapter duplicates account and category.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Meehalkoff, 2016-03-10
@Meehalkoff

I understood what the problem was, looking at the view screen, or rather at the names of the columns.
Solved like this:

String[] from = new String[] {"name","name:1","date", "amount"};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question