我想检索一行中包含姓名和电话号码的游标。这样做的方式很漂亮,没有任何循环吗?
Uri uri = ContactsContract.Data.CONTENT_URI;
getContentResolver().query(uri,
new String[] {ContactsContract.Data._ID, Phone.NUMBER, StructuredName.GIVEN_NAME}, null, null, null)
答案 0 :(得分:0)
我用来获取联系人的代码是:
Cursor cursor = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);
String Contactos =" CONTACTOS DEL TELEFONO "+cursor.getCount()+"\n";
while (cursor.moveToNext()) {
String name =cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Contactos+="Nombre: "+name+"\n"+
"Telefono: "+phoneNumber+"\n"+
"----------------------------\n";
}
然后将Contactos添加到textview,这就是全部! 见啊!