开发者

SimpleCursorAdapter / ListAdapter with Multiple Sources

开发者 https://www.devze.com 2023-02-12 18:23 出处:网络
Is it possible to build a ListAdapter having elements come from different sources (not 开发者_如何转开发just one cursor).

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());
}


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.


Yes. To merge cursors use MergeCursor

0

精彩评论

暂无评论...
验证码 换一张
取 消