本例介绍了SimpleCursorAdapter 的用法,可以参见Android ApiDemos示例解析(120):Views->Gallery->2. People,Android ApiDemos示例解析(10):App->Activity->QuickContactsDemo和Android ApiDemos示例解析(113):Views->Expandable Lists->2. Cursor(People)
SimpleCursorAdapter 的构造函数如下
public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
- context: context对象,可以使用activity。
- layout: layout 资源IDsimple_gallery_item.xml
- cursor: cursor对象,本例为通讯录cursor.
- from: 需要显示的列名数组
- to: 列对应的View 的id
// Get a cursor with all people
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
startManagingCursor(c);
ListAdapter adapter = new SimpleCursorAdapter(this,
// Use a template that displays a text view
android.R.layout.simple_list_item_1,
// Give the cursor to the list adatper
c,
// Map the NAME column in the people database to...
new String[] {People.NAME} ,
// The "text1" view defined in the XML template
new int[] {android.R.id.text1});
setListAdapter(adapter);
本文介绍如何使用SimpleCursorAdapter来填充ListView。通过实例演示了构造函数的参数设置,包括context、layout资源、Cursor对象、需要显示的列名及对应的View ID。


4854

被折叠的 条评论
为什么被折叠?



