Is there an easy way to delete items in a list using onLongPress
?
I would like to use OnGestureListener
- onLongPress
to listen for longpress
and to delete items in a list and update by adapter accordingly.
My problem is that if I use a custom adapter, then onlistItemclick
and onItemLongClick
conflict and longclicking does not trigger anything!
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(listmodified.this, "A long click detected", Toast.LENGTH_SHORT).show();
if (e.getAction()==MotionEvent.ACTION_DOWN)
{
OnItemLongClickListener itemDelListener = new OnItemLongClickListener(){
//@Override
public boolean onItemLongClick(AdapterView<?> parent, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
itemSelected=parent.getItemAtPosition(position).toString();
adapter.remove(itemSelected);
myList.remove(position);
adapter.notifyDataSetChanged();
Toast.makeText(listmodified.this, "IN LONGCLICK", Toast.LENGTH_SHORT).show();
return false;
}};
longClickedItem = -1;
}