How to detect double tap / click on Android ListView?

Do you know how to detect two touches / marks on ListView?

I am trying to call the following method with a double tap:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
}

Thanks in advance.

+5
source share
6 answers

Why aren't you using Long Touch? Or are you using this already for something else? Advantages over long touch double touch:

  • Long Press is the recommended interaction in the User Guide, double-tap is not.
  • This is what users expect; the user may not find the double-tap action, as he will not look for it.
  • It is already being processed in the API .
+4
source

, Actvity .

- , , , , , , , .

+1

, ListView , . , . , . / / , - , "". ? , , .

+1

I think that for double-tap or tap, you need to use the GestureDetector and its touch methods for single-tap and double-tap. here is the link for refrence http://www.linux.com/learn/tutorials/715651-make-android-multi-touch-coding-simpler-with-gesturedetector

0
source

My answer is based on this link and it works for me.


final GestureDetector gestureDectector = new GestureDetector(mContext, new GestureListener());
        listview.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                return false;
            }
            gestureDectector.onTouchEvent(event);
            return true;
        }
    });

GestureListener GestureDetector.SimpleOnGestureListener {

  public boolean onDoubleTap (MotionEvent e) {       int position = listview.pointToPosition((int) e.getX(), (int) e.getY());        ( < 0) {           return true;       }       Toast.makeText(mContext, " " + mList.get(position).content, Toast.LENGTH_SHORT).show();       return true;   }   @Override   public boolean onSingleTapConfirmed (MotionEvent e) {       int position = listview.pointToPosition((int) e.getX(), (int) e.getY());        ( < 0) {           return true;       }       Toast.makeText(mContext, "single-click" + mList.get(position).content, Toast.LENGTH_SHORT).show();       return true;   } } >
0
source

All Articles