我有一个使用自定义CursorAdaptor的SQLDatabase列表视图。我想回到我在listview中点击它们时用来创建项目的活动。我可以编辑条目。但是当我在CursorAdapter上实现OnItemClick方法和getItemId()时,没有任何事情发生,即使我不确定我是否正确。这是我的代码:
public void onItemClick(AdapterView<?> adapview, View view, int position, long rowId) {
Cursor c = adapter.retrieveRow(rowId); // retrieve row from Database
Intent edit = new Intent(this,NewItem.class);
edit.putExtra(DBAdapter.KEY_ID, rowId);
edit.putExtra(DBAdapter.Title, c.getString(c.getColumnIndex(DBAdapter.Title)));
edit.putExtra(DBAdapter.DATE, c.getString(c.getColumnIndex(DBAdapter.DATE)));
startActivity(edit);
}
public long getItemId(int id){
return id;
}
答案 0 :(得分:3)
我认为您需要在Listview上设置onItemClickListener,而不是尝试在Adapter类中实现它。
实施例
mListView = (ListView)findViewbyId(R.id.whatever)
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long rowId) {
Cursor c = adapter.retrieveRow(rowId); // retrieve row from Database
Intent edit = new Intent(this,NewItem.class);
edit.putExtra(DBAdapter.KEY_ID, rowId);
edit.putExtra(DBAdapter.Title, c.getString(c.getColumnIndex(DBAdapter.Title)));
edit.putExtra(DBAdapter.DATE, c.getString(c.getColumnIndex(DBAdapter.DATE)));
startActivity(edit);
}
});
这是你在做什么的?