已实现 OnItemLongClickListener。当 LongClicked 列表项时,我启用相关列表项的按钮。 LongClicked 按钮成功启用后,但不会触发 onListItemClick。如果我在没有 LongClicked 的情况下使用 onListItemClick,它会成功触发。如果在此之前触发了 LongClicked,为什么 onListItemClick 不会触发?
OnItemLongClickListener listener = new OnItemLongClickListener(){
public boolean onItemLongClick(AdapterView<?> av, View v, int position, long id) {
Account a = null;
a = (Account) av.getItemAtPosition(position);
Toast.makeText(AccountActivity.this, "Long Clicked : " + a.getAccountName(), Toast.LENGTH_LONG).show();
v.findViewById(R.id.btn_delete).setVisibility(View.VISIBLE);
return false;
}
};
getListView().setOnItemLongClickListener(listener);
public void onListItemClick(ListView l, View v, int position, long id) {
// Do something when a list item is clicked
Account a = null;
a = (Account) l.getItemAtPosition(position);
Toast.makeText(AccountActivity.this, a.getAccountName(), Toast.LENGTH_SHORT).show();
}
最佳答案
尝试像下面这样实现,
setOnItemLongClickListener
setOnItemClickListener
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
Account a = null;
a = (Account) av.getItemAtPosition(position);
Toast.makeText(AccountActivity.this, "Long Clicked : " + a.getAccountName(), Toast.LENGTH_LONG).show();
v.findViewById(R.id.btn_delete).setVisibility(View.VISIBLE);
return false;
}
});
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
Account a = null;
a = (Account) l.getItemAtPosition(position);
Toast.makeText(AccountActivity.this, a.getAccountName(), Toast.LENGTH_SHORT).show();
};
});
关于android: onListItemClick 在发生 onItemLongClick 时不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13762761/