你可以在setonitemclicklistener()
. 每当您单击列表视图的任何行时都会调用此函数。您单击的项目的位置/行号也会传递给此函数。
由于您使用数据库来填充您的列表,您可以这样做:
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
//SEE THIS FUNCTION
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/*
"position" is the position/row of the item that you have clicked
Query your table. Then move the cursor to "position" and get the
details. THen based on the details call a new activity.
*/
Cursor cur=db.query("your table name",null,null,null,null,null.null);
cur.moveToPosition(position); // see the argument int position
//Extract details from this row,process it and send to the respective activiy
});