android setOnItemClickListener 和 onItemClick 一直给我相同的 Toast

android setOnItemClickListener and onItemClick keeps giving me the same Toast

我正在尝试获取联系人的 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();
                            }
                      }

                 });  

您需要调用 cursor.moveToPosition(i) 而不是 cursor.moveToFirst()