In android, is it possible to move as forward or backward, when i click the corresponding Buttions?
<p>I have a doubt in android <code>ImageView</code>. I'm making a sample application to display the image in my drawable folder. First of all i used <code>Galleryview</code> and <code>Imageview</code> in my Layout to display the images, when i click the image in <code>GalleryView</code> the corresponding images is displayed in <code>ImageView</code>. Now i wish to implement like this, <img src="http://i.stack.imgur.com/yMC19.png" alt="enter image description here"></p>

<p>That is, I have set of 10 images in my <code>res/drawable</code> folder, <strong>the images will displayed among the corresponding button click, if i click Front button, the images in <code>ImageView</code> will displayed in forward manner, else i click Back button the images in <code>ImageView</code> moves Backward.</strong> is it possible to do like this. </p>

<p>I used the following code, but the image won't display</p>

<p><strong>main.xml:</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" &gt;

    &lt;ImageView
        android:id="@+id/imageView"
        android:layout_width="fill_parent"
        android:layout_height="333dp"
        android:src="@drawable/ic_launcher" /&gt;

    &lt;Gallery
        android:id="@+id/galleryView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" /&gt;

    &lt;RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" &gt;

        &lt;Button
            android:id="@+id/backBTN"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="B" /&gt;

        &lt;TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="imagePosition"
            android:textAppearance="?android:attr/textAppearanceMedium" /&gt;

        &lt;Button
            android:id="@+id/frontBTN"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/backBTN"
            android:layout_alignBottom="@+id/backBTN"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="F" /&gt;
    &lt;/RelativeLayout&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>My Java code  *<em>MainActivity.jav</em>*a is,</p>

<pre><code>package com.test.button.wallpaper;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    Button front, back;
    ImageView mImage;
    Gallery mGallery;
    int image_postion;
    private int[] gal = { R.drawable.img_2, R.drawable.img_3, R.drawable.img_4,
            R.drawable.img_5 };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        front = (Button) findViewById(R.id.frontBTN);
        back = (Button) findViewById(R.id.backBTN);
        mImage = (ImageView) findViewById(R.id.imageView);
        mGallery = (Gallery) findViewById(R.id.galleryView);
        mGallery.setAdapter(new ImageAdapter(this));
        mGallery.setVisibility(View.GONE);
        mGallery.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int loc,
                    long arg3) {
                // TODO Auto-generated method stub
                image_postion = loc;
                System.out.println("Inside the Gallery");

            }
        });

        back.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                int position = mGallery.getSelectedItemPosition();
                if (position &lt; mGallery.getCount() - 1)
                    mGallery.setSelection(position + 1);

            }
        });

        front.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                int position = mGallery.getSelectedItemPosition();
                if (position &gt;= 1)
                    mGallery.setSelection(position - 1);

            }
        });
    }

    public class ImageAdapter extends BaseAdapter {
        private Context ctx;
        int imageBackground;

        public ImageAdapter(Context c) {
            ctx = c;
            // TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
            // imageBackground = ta.getResourceId(
            // R.styleable.Gallery1_android_galleryItemBackground, 1);
            // ta.recycle();
        }

        @Override
        public int getCount() {

            return gal.length;
        }

        @Override
        public Object getItem(int arg0) {

            return arg0;
        }

        @Override
        public long getItemId(int arg0) {

            return arg0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setImageResource(gal[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(150, 120));
            iv.setBackgroundResource(imageBackground);
            return iv;
        }

    }
}
</code></pre>
