如何从列表视图中的uri获取联系人详细信息? 。我已从列表视图中获取所选联系人的联系人uri。以下代码片段是我尝试但不起作用的内容。更令人惊讶的是,记录声明甚至不执行!
@Override
public void onItemClick(
AdapterView<?> parent, View item, int position, long rowID) {
// Get the Cursor
Cursor cursor = ((SimpleCursorAdapter) parent.getAdapter()).getCursor();
// Move to the selected contact
cursor.moveToPosition(position);
// Get the _ID value
mContactId = cursor.getLong(CONTACT_ID_INDEX);
// Get the selected LOOKUP KEY
mContactKey = cursor.getString(CONTACT_KEY_INDEX);
// Create the contact's content Uri
mContactUri = Contacts.getLookupUri(mContactId, mContactKey);
// ListView Clicked item index
String id=new String();
String name = new String();
String hasPhone = new String();
int idx;
Cursor cursor1 = getActivity().getContentResolver().query(mContactUri, null, null, null, null);
{
idx = cursor1.getColumnIndex(ContactsContract.Contacts._ID);
id = cursor1.getString(idx);
idx = cursor1.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
name = cursor1.getString(idx);
idx = cursor1.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
hasPhone = cursor1.getString(idx);
}
Log.i("Phone Number","The phone number is: "+hasPhone);
Log.i("Name","The name is: "+name);
/*
* You can use mContactUri as the content URI for retrieving
* the details for a contact.
*/
}
这是单击列表视图项的特定时间的日志。
09-05 21:55:07.663: I/am_on_resume_called(25140): [0,com.laer.okgo.PersonListActivity]
09-05 21:55:07.738: W/Adreno-GSL(25140): <ioctl_kgsl_device_getproperty:663>: mmap failed: errno 22 Invalid argument
09-05 21:55:07.738: I/Adreno-EGL(25140): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I10246dbd022c719c705be805d5642cc8fdfbd2a2Date: 03/10/14
09-05 21:55:07.739: I/CanvasContext(25140): Initialized EGL, version 1.4
09-05 21:55:13.932: I/ImageButton(25140): Clicked!!
这是列表视图在ImageButton
09-05 21:55:13.941: I/am_on_paused_called(25140): [0,com.laer.okgo.PersonListActivity]
这是我单击列表项时的情况。
09-05 21:55:17.825: I/am_on_resume_called(25140): [0,com.laer.okgo.PersonListActivity]
也是奖金问题。如何更改列表视图的主题/样式?如果有人能指出我正确的方向,那就太好了!
答案 0 :(得分:0)
现在这真的是我的错。我点击了错误的UI元素。有两个名称相似的按钮。我没有意识到这一点。大声笑我搞砸了很多时间!浪费了很多时间...... 因此故事的寓意使您的UI / UX元素具有独特且易于区分的名称!