listview裡面item有button的,button要設置 android:focusable="false" ,listview裡面如果設置瞭 onitemlongclick事件,那麼onitemclick事件就不響應,我們隻需要在onitemlongclick中返回true就可以解決問題瞭
// 顯示長按刪除按鈕
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// 循環隱藏之前顯示的按鈕
if (btn_del_list != null && btn_del_list.size() > 0) {
for (int i = 0; i < btn_del_list.size(); i++) {
if (i != arg2) {
btn_del_list.get(i).setVisibility(View.GONE);
}
}
}
//當前的這個顯示
Button btn = (Button) arg1.findViewById(R.id.btn_del);
btn.setVisibility(View.VISIBLE);
return true;
}
});