Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand you correctly you simply need to use a gesture listener and then call the method you use to populate all the text views and imageviews you have with the next instance of information. </p> <p>I found this example to be very useful when I was learning about gesture recognition. </p> <p>First add the gesture listener to your public class myClass</p> <pre><code>import android.widget.Toast; public class myClass extends Activity implements OnGestureListener { </code></pre> <p>Then the following goes right afterwards so that we can listen for each touch event.</p> <pre><code> private static final int SWIPE_MIN_DISTANCE = 6; //120; private static final int SWIPE_MAX_OFF_PATH = 125; //250; private static final int SWIPE_THRESHOLD_VELOCITY = 100; //200; private GestureDetector gestureScanner;@ Override public boolean onTouchEvent(MotionEvent me) { return gestureScanner.onTouchEvent(me); } //@Override public boolean onDown(MotionEvent e) { //viewA.setText("-" + "DOWN" + "-"); return true; } //@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Left Swipe", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show(); } else if (e1.getY() - e2.getY() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Swipe up", Toast.LENGTH_SHORT).show(); } else if (e2.getY() - e1.getY() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Swipe down", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // nothing } return true; }@ Override public void onLongPress(MotionEvent e) { Toast mToast = Toast.makeText(getApplicationContext(), "Long Press", Toast.LENGTH_SHORT); mToast.show(); } //@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { //viewA.setText("-" + "SCROLL" + "-"); return true; } //@Override public void onShowPress(MotionEvent e) { //viewA.setText("-" + "SHOW PRESS" + "-"); } //@Override public boolean onSingleTapUp(MotionEvent e) { Toast mToast = Toast.makeText(getApplicationContext(), "Single Tap", Toast.LENGTH_SHORT); mToast.show(); return true; } </code></pre> <p>You can put the methods you use to call the previous or next instance inside the relevant listener where the toast is. </p> <p>You can adjust the sensotivity of the swipes by changing these variables</p> <pre><code> private static final int SWIPE_MIN_DISTANCE = 6; //120; private static final int SWIPE_MAX_OFF_PATH = 125; //250; private static final int SWIPE_THRESHOLD_VELOCITY = 100; //200; </code></pre> <p>I hope this helps out. </p> <p>Edit:</p> <p>Sorry for the mix up, your onCreate should include gestureScanner = new GestureDetector(this);</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.product_details); setContent(); gestureScanner = new GestureDetector(this); } </code></pre> <p>That should get it working except for the visual effect. You can experiment with using a ScrollView to help with the slide. </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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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