我正在尝试为我的适配器设置 onItemClickListener,它可以工作,但现在我不知道如何获得被点击的对象?我有一个带有注释的列表,单击时我想用单击的注释的 id 开始新的活动。
private DatabaseHelper dbhelper;
SimpleCursorAdapter adapter = null;
public OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "it works", Toast.LENGTH_SHORT).show();
}
};
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.first);
dbhelper = new DatabaseHelper(getApplicationContext());
Cursor cursor = dbhelper.getAllNotes();
startManagingCursor(cursor);
ListView lv = (ListView)findViewById(android.R.id.list);
String[] columns = new String[] {"NoteTitle", "NoteDate"};
int[] to = new int[] { R.id.title_entry, R.id.date_entry};
adapter = new SimpleCursorAdapter(this, R.layout.note_entry, cursor, columns, to);
lv.setAdapter(adapter);
lv.setOnItemClickListener(listener);
}
...
public Cursor getAllNotes()
{
SQLiteDatabase db=this.getReadableDatabase();
return db.query(noteTable, new String [] {colID, colTitle, colDesc, colDate}, null, null, null, null, null);
}
...
我应该在 onItemClick 中插入什么来获取注释 id(Toast 仅用于检查它是否有效)?我正在寻找答案,但我没有找到;/
提前致谢
格雷格