本例和上例類似,不同的是是使用android.R.layout.simple_list_item_2 Layout 顯示列表項,
android.R.layout.simple_list_item_2.xml 中含有兩個TextView,其id 分別為 android.R.id.text1, android.R.id.text2.
對於本例,兩個TextView可以分別來顯示聯系人的姓名和電話:
[java
Cursor c = getContentResolver().query(Phones.CONTENT_URI,
null, null, null, null);
startManagingCursor(c);
// Map Cursor columns to views defined in simple_list_item_2.xml
ListAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, c,
new String[] { Phones.NAME, Phones.NUMBER },
new int[] { android.R.id.text1, android.R.id.text2 });
setListAdapter(adapter);
Cursor c = getContentResolver().query(Phones.CONTENT_URI,
null, null, null, null);
startManagingCursor(c);
// Map Cursor columns to views defined in simple_list_item_2.xml
ListAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, c,
new String[] { Phones.NAME, Phones.NUMBER },
new int[] { android.R.id.text1, android.R.id.text2 });
setListAdapter(adapter);