当前位置:操作系统 > 安卓/Android >>

Android ApiDemos示例解析(170):Views->Lists->3. Cursor (Phones)

本例和上例类似,不同的是是使用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);

 \

 

 

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,