您可以在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
});
開關似乎一個可能的解決方案,如果你有一個定義的所有可能的類型的列表。如果你不這樣做,試着做一個。有解決方案,但它們比交換機更復雜。 – purtip31
請看看這個........ http://stackoverflow.com/a/11096757/804447 –