0

I have a button that I click and that shows contacts. It displays the name, but not the number of a selected contact...

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
                startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    public void onActivityResult(int reqCode, int resultCode, Intent data) {
        super.onActivityResult(reqCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            Uri contactData = data.getData();
            Cursor c = managedQuery(contactData, null, null, null, null);
            if (c.moveToFirst()) {
                String name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
                contactName.setText(name);

                Something here !!!!!!!!!!!!!!!!!!!!!!!!

                contactName.setText(number);
            }
        }
    }
}

It String the NAME but how can I get the phone number?

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
        while (phones.moveToNext())
        {
            String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String number=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

            contactName.setText(name);
            contactNumber.setText(number);
        }
    }

With this code it opens my contacts. I touch one, but it always display the LAST name and number that I have added to contacts.

For example, I touch Adrian (22222222) and it shows Paul (33333333) which is the last person that I have added.

What should I do?

4

1 回答 1

0

String phoneNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

于 2013-09-02T19:33:28.030 回答