title: android image changed with button click in sequence
body: <p>I would like to make a simple app with an image, and two buttons under it. A next button, and a previous button. When they click "next" it will change the picture to the next picture. When they click "previous", it will change the picture to the previous picture. My activity name is "imagescreen" and my button ID's are "previous" and "next". My imageview ID is "ImageView".</p>
  
  <p>I can't seem to make this work. I have tried this, but my app is crashing. Sorry I am new to this and trying my best.</p>
  
  <p>I would also like to make it for the "previous" button is grayed out/disabled when on the first image (which is resource r1.png) but can't figure out how to do that.</p>
  
  <pre><code>public class imagescreen extends Activity implements View.OnClickListener {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_imagescreen);
  
      previous = (Button) findViewById(R.id.previous);
      previous.setOnClickListener(this);
  
      next = (Button) findViewById(R.id.next);
      next.setOnClickListener(this);
  
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.swipepage, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  @Override
  public void onClick(View view) {
  
      switch (view.getId()) {
          case R.id.next:
              if (a == 0) {
                  image.setImageResource(R.drawable.r2);
                  a = 1;
              } else if (a == 1) {
                  image.setImageResource(R.drawable.r3);
                  a = 2;
              } else if (a == 2) {
                  image.setImageResource(R.drawable.r1);
                  a = 3;
          case R.id.previous:
              a--;
              View previous;
              previous.performClick();
              break;
      }
  }
  </code></pre>