这是我的代码,通过单击列表项给我联系人的姓名和电话号码:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final String contactName = cursor.getString(cursor.getColumnIndexOrThrow("DISPLAY_NAME"));
Cursor contCursor =(Cursor) listStarred.getItemAtPosition(position);
String strid = contCursor.getString(contCursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
ContentResolver cr = getContentResolver();
String name = null;
String lname ="...";
contCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"='"+strid+"'",
null, null);
int phoneNumberIndex = contCursor
.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER);
Log.d("Count", String.valueOf(contCursor.getCount()));
if (contCursor != null) {
Log.v("CurNotNull", "Cursor Not null");
try {
if (contCursor.moveToNext()) {
Log.v("MoveToFirst", "Moved to first");
Log.v("CheckMTF", "Cursor Moved to first and checking");
lname = contCursor.getString(phoneNumberIndex);
Toast.makeText(getApplicationContext(), contactName + " " + lname, Toast.LENGTH_SHORT).show();
}
} finally {
Log.v("Finally", "In finally");
contCursor.close();
}
}
}
上面的代码似乎可以正常工作,但是如何不获取一个电话号码来获取包含所有联系人号码的列表呢?需要进行哪些更改才能获得包含所选联系人的号码(和每个类型)的数组?