Note that there are some explanatory texts on larger screens.

plurals
  1. POSwipe to delete listitem
    primarykey
    data
    text
    <p>I would like to implement a swipe gesture to delete rows in a <code>ListView</code> similar to the android notifications.</p> <p>Right now all I have is a <code>ListView</code> with an <code>onTouchListener</code> - that said, I already have swipe detection working.</p> <pre><code>gestureDetector = new GestureDetector(this, new GestureListener()); onTouchListener = new TouchListener(); listview.setOnTouchListener(onTouchListener); </code></pre> <p>My <code>GestureListener</code> class: </p> <pre><code>protected class GestureListener extends SimpleOnGestureListener { private static final int SWIPE_MIN_DISTANCE = 150; private static final int SWIPE_MAX_OFF_PATH = 100; private static final int SWIPE_THRESHOLD_VELOCITY = 100; private MotionEvent mLastOnDownEvent = null; @Override public boolean onDown(MotionEvent e) { mLastOnDownEvent = e; return super.onDown(e); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if(e1 == null){ e1 = mLastOnDownEvent; } if(e1==null || e2==null){ return false; } float dX = e2.getX() - e1.getX(); float dY = e1.getY() - e2.getY(); if (Math.abs(dY) &lt; SWIPE_MAX_OFF_PATH &amp;&amp; Math.abs(velocityX) &gt;= SWIPE_THRESHOLD_VELOCITY &amp;&amp; Math.abs(dX) &gt;= SWIPE_MIN_DISTANCE ) { if (dX &gt; 0) { Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Left Swipe", Toast.LENGTH_SHORT).show(); } return true; } else if (Math.abs(dX) &lt; SWIPE_MAX_OFF_PATH &amp;&amp; Math.abs(velocityY)&gt;=SWIPE_THRESHOLD_VELOCITY &amp;&amp; Math.abs(dY)&gt;=SWIPE_MIN_DISTANCE ) { if (dY&gt;0) { Toast.makeText(getApplicationContext(), "Up Swipe", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "Down Swipe", Toast.LENGTH_SHORT).show(); } return true; } return false; } } </code></pre> <p>My <code>TouchListener</code> class:</p> <pre><code>protected class TouchListener implements View.OnTouchListener { @Override public boolean onTouch(View v, MotionEvent e) { if (gestureDetector.onTouchEvent(e)){ return true; }else{ return false; } } } </code></pre> <p>Are there some tutorials / examples on that?</p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload