I'd like to have both type of clicks on a listView - onClick and LongClick.
I've implemented it like this:
this.listViewSub = (ListView) this.findViewById(R.id.listsub);
this.listViewSub.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(final AdapterView parent, final View view, final int position,
final long id) { ... } });
// listen to long click - to share texts
this.listViewSub.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) { ... } });
But it does't fire the Long Click. Anyone has any idea why?
onLongClick returns true if the callback consumed the long click, false otherwise. So if the event is handled by this method, return true.
@Vadim, are your listview's adapter is extends from BaseAdapter? if yes, then also need to set convertView.setLongClickable(true); in the getView().
For me, I had to set
android:longClickable="true"
in the XML file that contains my ListView row layout (not ListView layout) for the item to be long-clickable.You have to enable the
LongClickable
and