0

このコードを使用しましたが、結果はリストビューで選択した名前の情報ではなく、他の名前の情報です。

contactmanager.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);
}

ContactEditor.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);
        }
    }
}   
4

1 に答える 1

0

You must ask for the id that you want. This asks for every contact and only displays the last one:

Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (mRowId != null)         
{

Try something like this:

if (mRowId != null)         
{
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, 
            ContactsContract.Contacts._ID + "=" + mRowId, null, null);
于 2012-05-12T19:07:28.567 に答える