0

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();
                            }
                      }

                 });  
CHarris
  • 2,693
  • 8
  • 45
  • 71

1 Answers1

1

You need to call cursor.moveToPosition(i) instead of cursor.moveToFirst()

Victor Nidens
  • 474
  • 1
  • 4
  • 11