If you understand correctly, you just need to use a gesture listener, and then call the method that you use to populate all the textual representations and images that you have with the following copy of the information.
I found this example very useful when I found out about gesture recognition.
First add a gesture listener to your public myClass class
import android.widget.Toast; public class myClass extends Activity implements OnGestureListener {
Then immediately follows the following so that we can listen for each touch event.
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()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Left Swipe", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show(); } else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Swipe up", Toast.LENGTH_SHORT).show(); } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > 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; }
You can use the methods used to call the previous or next instance inside the corresponding listener where the toast is located.
You can adjust the sensitivity of the fingers by changing these variables.
private static final int SWIPE_MIN_DISTANCE = 6;
Hope this helps.
Edit:
Sorry for the confusion, your onCreate should include gestureScanner = new GestureDetector (this);
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.product_details); setContent(); gestureScanner = new GestureDetector(this); }
This should make it work, except for the visual effect. You can experiment using ScrollView to help with the slide.