0

ListViewこのような特定のアイテムを表示するダイアログがあります

d = new Dialog(this);
d.setContentView(R.layout.dialog_layout);
d.setTitle("Select Bowler " + String.valueOf(bakerList.size()+1));

ListView lv3 = (ListView)d.findViewById(R.id.dialog_list);
Cursor c3 = getContentResolver().query(TeamBowlers.CONTENT_URI,new String[] {TeamBowlers.ID,TeamBowlers.SUB,TeamBowlers.BOWLER_ID,TeamBowlers.CAPTAIN}
    ,TeamBowlers.TEAM_ID + "=?",new String[] {String.valueOf(teamSelectedID)},TeamBowlers.POSITION + " ASC");                                       

if(c3.moveToFirst() && c3 != null){
    SimpleCursorAdapter adapter2 = new ImageAdapter(this,R.layout.row,c3
            ,new String[] {TeamBowlers.ID,TeamBowlers.SUB,TeamBowlers.BOWLER_ID},new int[] {R.id.icon,R.id.bowler_txt,R.id.bowler_txt2});

    lv3.setAdapter(adapter2);
    lv3.setOnItemClickListener(new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> arg0, View v,int position, long id) {
            bakerList.add(id);
            updateName(id);
        }

    });
    d.show();
}

問題は、リスト内のアイテムをクリックすると、返されるIDがデータベースからのIDではなく、基本的にインデックスを返すだけであるということです。

データベースの「_id」列をバインドしないのはなぜですか?

4

1 に答える 1

0
why is it not binding my "_id" column of my database?

私はそれが真実ではないと思います。それidonItemClick実際にrow idはリストビューであり、idあなたのからではありませんcursor

行データが必要な場合は、次のようなことができますonItemClick

Cursor cursor = ((SimpleCursorAdapter) arg0).getCursor();
cursor.moveToPosition(position);
long _id= cursor.getLong(cursor.getColumnIndex("id");
于 2012-12-04T02:56:06.127 に答える