I am storing two images in an array, the images come up but what I am trying to achieve is when the user swipes the screen to the right the second image comes up and when swiped left back to the first image. I am quite new to android app development some help would be much appreciated. At the moment all that happens is when the user clicks the image it goes to the second image and thats it.
I have also added my code:
public class ScrollingQuran extends Activity {
private ImageView imgView;
private Integer[] Imgid = {
R.drawable.page1, R.drawable.page2
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.qurangallery);
imgView = (ImageView)findViewById(R.id.ImageView01);
imgView.setImageResource(Imgid[0]);
imgView.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
ImageView iv = (ImageView) v;
if (event.getAction() == MotionEvent.AXIS_VSCROLL) {
iv.setImageResource(R.drawable.page2);
return true;
} else if (event.getAction() == MotionEvent.AXIS_HSCROLL) {
iv.setImageResource(R.drawable.page2);
return true;
}
return false;
}
});
I think this code will help you.In this transimg1 is an imageswitcher
Here is a blog from Dustin Graham with more examples: http://developingandroid.blogspot.in/2009/09/implementing-swipe-gesture.html