2013-09-27 38 views
-1

當我要求對接觸的一些領域,我需要問單獨如何獲取所有聯繫人信息而不詢問特定字段?

每個字段,例如,如果我要問的ID和姓名,我需要把它寫

ContentResolver cr = getContentResolver(); 
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 

String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); 
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 

但在這種情況下,我需要編寫長的代碼來訪問每個聯繫人字段並檢查這個字段是否填滿。

是否有某種方式來避免這一點,並讓所有的聯繫人信息一次?

回答

1

嘗試像

for (String colName:cur.getColumnNames()) 
{ 
    String a = colName; 
    String b = cur.getString(cur.getColumnIndex(colName)); 

    //now you have the name of the column in variable a, and the data in variable b 
} 
相關問題