2010-07-16 46 views

回答

0

試試這個您的活動或其他應用程序組件中:

ContentResolver cr = getContentResolver(); 
Cursor cur = cr.query(People.CONTENT_URI, null, null, null, null); 
if (cur.getCount() > 0) { 
     while (cur.moveToNext()) { 
       String name = formatName(cur.getString(cur 
           .getColumnIndex(People.DISPLAY_NAME))); 
       // Do something with name. 
     } 
} 
0
First you have to add `ListView` in your layout file 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ListView 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

現在,在使用這個代碼的Activity

Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null); 
    startManagingCursor(c); 

    ListAdapter adapter = new SimpleCursorAdapter(this, 
      android.R.layout.simple_list_item_1, 
      c, 
      new String[] {People.NAME} , 
      new int[] {android.R.id.text1}); 
    setListAdapter(adapter); 
相關問題