0

I've got a problem with putting data from 2 cursors in one listview.

I understund that it's impossible to do it with just SimpleCursorAdapter, but I can't find method, how to do this.

cursor1 = db.getSelect(selection1);

cursor2 = db.getSelect(selection2);

scAdapter1 = new SimpleCursorAdapter(this, R.layout.item1, cursor1, from, to);

scAdapter2 = new SimpleCursorAdapter(this, R.layout.item2, cursor2, from, to);

listView.setAdapter(???);

5
  • listView.setAdapter(cwac-merge) or even better use 1 cursor db.getSelect(selection1 | selection2)
    – Selvin
    Oct 23, 2013 at 9:46
  • rather use array adapter put your data of both cursor to ArrayList<Hashmap<String,String>> and pass to array adapter. Oct 23, 2013 at 9:54
  • CursorAdapter is much better in the terms of memory usage ...
    – Selvin
    Oct 23, 2013 at 9:56
  • Selvin, I can't use 1 cursor because they have different layouts. I undestand how to do with with hashmap, but its better to do with Cursor. Selvin, how can i build cwac method?
    – tadvas
    Oct 23, 2013 at 10:05
  • Can you change the constructor of SimpleCursorAdapter; to get a List; Instead of cursor? you can have a list and add the data which back from getSelect Method Oct 23, 2013 at 10:12

2 Answers 2

0

use CursorAdapter (not SimpleCursorAdapter) and MergeCursor( Cursor[] cursors)

2
  • Thanx, done. But got another problem. How to put MergeCursor into ListView?
    – tadvas
    Oct 23, 2013 at 10:53
  • MergeCursor is a Cursor, so use it with CursorAdapter
    – pskink
    Oct 23, 2013 at 10:57
0

Try to use MergeCursor. You might add fake column type to your selection to distinguish data in your adapter.

BUT. Google Dialer application doesn't use MergeCursor, but rather uses complex listview adapter.

Another way is to use cwac-merge lib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.