android setOnItemClickListener和onItemClick不断给我相同的Toast

时间:2016-04-23 09:20:43

标签: android onitemclick

我正在尝试在单击其单元格时获取联系人的CONTACT_ID。你知道我怎么做吗?

目前,Toast一直在给我,无论我点击列表中的哪个单元格,'215',这是我第一次联系的CONTACT_ID。这是我的代码:

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

                 });  

1 个答案:

答案 0 :(得分:1)

您需要致电cursor.moveToPosition(i)而不是cursor.moveToFirst()