我有這樣的代碼
this.mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Log.v(TAG,"loul");
}
});
但它沒有工作
,所以我有中庸之道把onItemSelectedListener下,它工作OO:
this.mListView.setItemsCanFocus(false);
this.mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Log.v(TAG,"loul");
}
});
//listener for nothing but it allow OnItemClickListener to work
this.mListView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
我有同樣的問題,上述解決方案適用於在該行檢測點擊,但我有我的自定義的ListView行2個按鈕。我怎麼知道哪個按鈕被點擊了? 謝謝 – longhairedsi 2010-09-10 11:47:53
謝謝!!!你真的幫助我了! – 2013-07-24 06:06:21
@longhairedsi:請將以下代碼添加到getView()方法中 button1.setFocusable(false); button2.setFocusable(false); button1.setFocusableInTouchMode(false); button2.setFocusableInTouchMode(false); button1.setOnClickListener(this); button2.setOnClickListener(this); 在您的適配器(或您希望的地方)中實現您的點擊監聽器按鈕 設置列表視圖的點擊監聽器也..... 現在檢查您的點擊將適用於這兩種..... listview至於按鈕也 – 2013-09-26 10:34:33