我已经使用了这段代码,但结果不是我在列表视图中选择的名称的信息,而是来自其他名称的信息。
联系人管理器.java
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, ContactEditor.class);
i.putExtra(ContactsContract.Contacts._ID, id);
startActivityForResult(i, 2);
}
联系人编辑器.java
private Long mRowId;
mRowId = savedInstanceState != null ? savedInstanceState.getLong(ContactsContract.Contacts._ID):null;
if (mRowId == null){
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(ContactsContract.Contacts._ID):null;
}
populateFields();
private void populateFields(){
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
if (mRowId != null)
{
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
mContactNameEditText.setText(name);
}
}
}