title: How to use findViewById variable in another method. Java Android
body: <p>I am very new to programming and am teaching myself so sorry if my code is ugly.  </p>
  
  <p>I am trying to create a menu like screen that has left and right arrow buttons that change the picture displayed.  I want to make it so when your on the first image the left arrow is gone and when on the last image is displayed the right arrow is gone.</p>
  
  <p>I have tried to do this a lot of different ways but always end up needing a variable somewhere where it cannot be resolved.  In the code posted the error is in the switch statement and I other ways I have tried to code it the unresolved variable error would be in the onClickListener.</p>
  
  <p>You don't have to code it for me, just let me know what concept I am missing and I will study up on it.</p>
  
  <p>Thanks</p>
  
  <pre><code>    package com.mystuff.mymenu;
  
      import android.app.Activity;
      import android.os.Bundle;
      import android.view.View;
      import android.view.View.OnClickListener;
      import android.widget.ImageButton;
      import android.widget.ImageView;
  
  
  
  public class PictureMenu extends Activity implements OnClickListener{
  
  int setView = 1;    
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.picture_menu);  
  
      menuSet(setView);
  
  ImageButton right = (ImageButton) findViewById(R.id.rightButton);
  ImageButton left = (ImageButton) findViewById(R.id.leftButton);
  right.setOnClickListener(this);
  left.setOnClickListener(this);
  
  }       
  @Override
  public void onClick(View v) {
  if(v.getId() == R.id.rightButton){
      setView ++;
      menuSet(setView);
  if(v.getId() == R.id.rightButton){
      setView ++;
          menuSet(setView);
  }
      }   
      }
  
  
  private void menuSet(int setView) {
  
      ImageView picture1 = (ImageView) findViewById(R.id.picture1);
      ImageView picture2 = (ImageView) findViewById(R.id.picture2);
      ImageView picture3 = (ImageView) findViewById(R.id.picture3);
      ImageView picture4 = (ImageView) findViewById(R.id.picture4);
  
      switch(setView){
      case 1: 
          left.setVisibility(View.GONE);  //ERROR left cannot be resolved
          right.setVisibility(View.VISIBLE); //ERROR right cannot be resolved
          picture1.setVisibility(View.VISIBLE);
          picture2.setVisibility(View.GONE);
          picture3.setVisibility(View.GONE);
          picture4.setVisibility(View.GONE);
          break;
      case 2:
          left.setVisibility(View.VISIBLE);  //ERROR left cannot be resolved
          right.setVisibility(View.VISIBLE);  //ERROR right cannot be resolved
          picture1.setVisibility(View.GONE);
          picture2.setVisibility(View.VISIBLE);
          picture3.setVisibility(View.GONE);
          picture4.setVisibility(View.GONE);
          break;
      case 3: 
          left.setVisibility(View.VISIBLE);  //ERROR left cannot be resolved
          right.setVisibility(View.VISIBLE);  //ERROR right cannot be resolved
          picture1.setVisibility(View.GONE);
          picture2.setVisibility(View.GONE);
          picture3.setVisibility(View.VISIBLE);
          picture4.setVisibility(View.GONE);
          break;
      case 4: 
          left.setVisibility(View.VISIBLE); //ERROR left cannot be resolved
          right.setVisibility(View.GONE); //ERROR right cannot be resolved
          picture1.setVisibility(View.GONE);
          picture2.setVisibility(View.GONE);
          picture3.setVisibility(View.GONE);
          picture4.setVisibility(View.VISIBLE);
          break;
      default:
          left.setVisibility(View.GONE);  //ERROR left cannot be resolved
          right.setVisibility(View.VISIBLE);  //ERROR right cannot be resolved
          picture1.setVisibility(View.VISIBLE);
          picture2.setVisibility(View.GONE);
          picture3.setVisibility(View.GONE);
          picture4.setVisibility(View.GONE);
          break;
  }       
  
  
  }
  
  
  
  }
  </code></pre>