当我在联系上询问某个字段时,我需要单独询问每个字段
例如,如果我需要询问我需要写的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));
但是在这种情况下,我需要编写长代码来访问每个联系人字段并检查该字段是否填满。
有没有办法避免这种情况并立即获取所有联系信息?
答案 0 :(得分: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
}