dev101
dev101

Reputation: 353

SimpleCursorAdapter / ListAdapter with Multiple Sources

Is it possible to build a ListAdapter having elements come from different sources (not just one cursor).

// Build up a list of names
// Query table1.name
// Query table2.name
// Create a ListAdapter passing in the list of names.

Here's the example for creating a cursor from a single table:

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, new String[] { NAME }, new int[] { 
android.R.id.text1 });
setListAdapter(adapter);
adapter.setFilterQueryProvider(m_filterQueryProvider);
if (rememberLastConstraint && m_filterQueryProvider.getConstraint() != null) {
    adapter.getFilter().filter(m_filterQueryProvider.getConstraint());
}

Upvotes: 1

Views: 990

Answers (2)

Ravi Vyas
Ravi Vyas

Reputation: 12375

One method would be to compile all the data for the ListView in a data structure outside the ListView adapter and then pass it to the ListView and called notify data set changed. This way you can get data from different type of sources into the ListView.

Upvotes: 2

pawelzieba
pawelzieba

Reputation: 16082

Yes. To merge cursors use MergeCursor

Upvotes: 2

Related Questions