use*_*714 4 lookup android list contacts details
我想从联系人列表视图中获取几个联系人详细信息.我有这个代码:
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id) {
//HERE I WANT TO GET CONTACT DETAILS FROM THE ID PARAMETER
Uri lookupUri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, Uri.encode(id));
Cursor c = getContentResolver().query(lookupUri, new String[]{Contacts.DISPLAY_NAME}, null,null,null);
try {
c.moveToFirst();
String displayName = c.getString(0);
} finally {
c.close();
}
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个异常:IllegalArgumentException,无效的查找ID(当我从游标调用查询方法时).所以我不知道如何从项目列表中获取有效的查找ID.
任何的想法?谢谢!
use*_*305 10
这id
意味着,contact id
您想要获取联系人详细信息的A,
获取特定电话号码的简单代码contact id
就像,
// Build the Uri to query to table
Uri myPhoneUri = Uri.withAppendedPath(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, id);
// Query the table
Cursor phoneCursor = managedQuery(
myPhoneUri, null, null, null, null);
// Get the phone numbers from the contact
for (phoneCursor.moveToFirst(); !phoneCursor.isAfterLast(); phoneCursor.moveToNext()) {
// Get a phone number
String phoneNumber = phoneCursor.getString(phoneCursor
.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
sb.append("Phone: " + phoneNumber + "\n");
}
}
Run Code Online (Sandbox Code Playgroud)
所以,从你的问题我不得不怀疑你在你的uri唱歌的id参数,只是在我的例子中,id是字符串类型...
希望你能理解它.
更新: Uri.encode(id)
而不是仅以字符串格式传递id.
谢谢..
归档时间: |
|
查看次数: |
11816 次 |
最近记录: |