获取具有特定ID的行的ListView中的位置

Foe*_*nix 0 android click android-listview simplecursoradapter

我有一个ListView,SimpleCursorAdapter我想知道如何获得ListView一个身份证的位置?我需要它来执行单击列表中的特定行,如下所示

lv.performItemClick(lv, pos, lv.getItemIdAtPosition(pos));
Run Code Online (Sandbox Code Playgroud)

Luk*_*rog 6

迭代你Cursor使用的SimpleCursorAdapter并检查id:

if (cursor.moveToFirst()) {
    while (!cursor.isAfterLast) {
         if (cursor.getLong(/*the index of the _id column*/) == theTargetId) {
              theWantedPosition = cursor.getPosition();
              break; 
         }
         cursor.moveToNext();
    } 
}
lv.performItemClick(lv, theWantedPosition, lv.getItemIdAtPosition(theWantedPosition));
Run Code Online (Sandbox Code Playgroud)