我有一个对话框,显示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”列?
答案 0 :(得分:0)
why is it not binding my "_id" column of my database?
我想这不是真的。 id
中的onItemClick
实际上是列表视图中的row id
,而不是id
cursor
如果你想要行数据,可以在onItemClick
Cursor cursor = ((SimpleCursorAdapter) arg0).getCursor();
cursor.moveToPosition(position);
long _id= cursor.getLong(cursor.getColumnIndex("id");