Reputation: 2793
I'm trying to get the contact's CONTACT_ID, when their cell is clicked. Do you know how I can do this?
At present, Toast keeps giving me, no matter which cell in the list I click, '215', which is the CONTACT_ID of my first contact. Here's my code :
// Select item on listclick
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (cursor != null) {
cursor.moveToFirst();
String usercontactid = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
Toast.makeText(getApplicationContext(), usercontactid, Toast.LENGTH_LONG).show();
}
}
});
Upvotes: 0
Views: 36
Reputation: 474
You need to call cursor.moveToPosition(i)
instead of cursor.moveToFirst()
Upvotes: 1