Not getting previous image in 1st case itself
<p>Am beginner to android..I developed an app like if i press prev and next button it will display prevous and next images....</p>

<p>But I had issue in my app..The problem here was, if app execute i set an current image source as <strong>IMAGE_IDS[0]</strong>... So that if i pressed left arrow app gets <strong>force close</strong>, actually if i press left arrow it shows last image in the <strong>array IMAGE_IDS</strong>... Any idea ???   Thank You !</p>

<pre><code>  public class MainActivity extends Activity  implements OnClickListener{

    ImageButton play;

    ImageButton ib_left_arrow, ib_right_arrow;  

    ImageView slidingimage;

    Animation rotateimage;  


    private int[] IMAGE_IDS = { R.drawable.image1, R.drawable.image2,
        R.drawable.image3};

    int imglength=IMAGE_IDS.length;

    int img_position;

    int img_minus;

    int img_plus;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.movies);


    ib_left_arrow = (ImageButton) findViewById(R.id.iv_left_arrow);
    ib_right_arrow = (ImageButton) findViewById(R.id.iv_right_arrow);

    ib_left_arrow.setOnClickListener(this);
    ib_right_arrow.setOnClickListener(this);

    slidingimage = (ImageView) findViewById(R.id.ImageView3_Left);
    slidingimage.setImageResource(IMAGE_IDS[0]);

}



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub


switch (v.getId()) {

case R.id.iv_left_arrow:


    img_minus=--img_position;

    slidingimage.setImageResource(IMAGE_IDS[img_minus% IMAGE_IDS.length]);

    rotateimage = AnimationUtils.loadAnimation(this,R.anim.slide_in_left);

    slidingimage.startAnimation(rotateimage);

    break;



case R.id.iv_right_arrow:

    img_plus=++img_position;

    slidingimage.setImageResource(IMAGE_IDS[img_plus% IMAGE_IDS.length]);

    rotateimage = AnimationUtils.loadAnimation(this,R.anim.slide_in_right);

    slidingimage.startAnimation(rotateimage);


    break;              


    }
  }


 }
</code></pre>
