title: How to access EditText references outside the AlertBox and onClickListener
body: <p>I have declared an EditText Array "ed[][]" in alertBox which is in onClickListener. I used this ed[][] reference in another onClickListener method in the same activity, but it always gives the following error</p>
  
  <p><strong>ed cannot be resolved to a variable</strong></p>
  
  <p>Here is my code:   </p>
  
  <pre><code>private EditText nR,nC,nR1,nC1;
  EditText[][] arr;
  private Button submit,b2,bmul;
  private LinearLayout matrix,matrix2;
  int rows,cols,a1=1,b1=1,a3,b3;
  private LinearLayout layout,layout2;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.dimensions);
  
          matrix = (LinearLayout) findViewById(R.id.matrix);
          matrix2 = (LinearLayout) findViewById(R.id.matrix2);
          matrix.setOrientation(LinearLayout.VERTICAL);
          matrix2.setOrientation(LinearLayout.VERTICAL);
          submit = (Button) findViewById(R.id.button1);
          b2 = (Button) findViewById(R.id.button2);
          bmul=(Button)findViewById(R.id.mul);
          submit.setOnClickListener(this);
          b2.setOnClickListener(this);
  
  }
  @Override
  public void onClick(View arg0) {
      // TODO Auto-generated method stub
      switch(arg0.getId()){
      case R.id.button1:
  
         //creatDialog(matrix,submit);
          AlertDialog.Builder alert = new AlertDialog.Builder(this);
  
          LayoutInflater inflater = this.getLayoutInflater();
  
  
          alert.setTitle("Define Dimensions");
          alert.setMessage("Assign Numbers of Rows and Columns to Matrix");
  
          //Set an EditText view to get user input 
  
          final View tex =inflater.inflate(R.layout.dialog_dimension,null);
  
          alert.setView(tex);
  
  
          nR=(EditText)tex.findViewById(R.id.R2);
          nC=(EditText)tex.findViewById(R.id.C2);
  
          alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
  
              a1 = Integer.parseInt(nR.getText().toString());
              b1 = Integer.parseInt(nC.getText().toString());
              submit.setText(""+a1+"x"+b1);
  
              //multipleDimension(a1,b1,mat);
  
              **final EditText ed[][] = new EditText[a1][b1];**  
              matrix.removeAllViews();
              for (int i = 0; i &lt; a1; i++) {
              layout = new LinearLayout(
                      Dimensions.this);
  
              layout.setOrientation(LinearLayout.HORIZONTAL);
  
              for (int j = 0; j &lt; b1; j++) {
  
                  ed[i][j] = new EditText(Dimensions.this);
  
                  //ed[i][j].setId(+(i)+(j));
  
                  ed[i][j].setLayoutParams(new LayoutParams(
                          LayoutParams.WRAP_CONTENT,
                          LayoutParams.WRAP_CONTENT));
                  ed[i][j].setHint("a"+(i+1)+(j+1));
                  ed[i][j].setTextColor(Color.RED);
  
  
  
                  layout.addView(ed[i][j]);
              }
  
              matrix.addView(layout);
  
              }
  
  
            }
          }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  dialog.dismiss();
              }
          }).show();
  
  
      break;
  
      case R.id.button2:
  
          //creatDialog(matrix2,b2);
  
           //creatDialog(matrix,submit);
          AlertDialog.Builder alert1 = new AlertDialog.Builder(this);
  
          LayoutInflater inflater1 = this.getLayoutInflater();
  
  
          alert1.setTitle("Define Dimensions");
          alert1.setMessage("Assign Numbers of Rows and Columns to Matrix");
  
          //Set an EditText view to get user input 
  
          final View tex1 =inflater1.inflate(R.layout.dialog_dimension,null);
  
          alert1.setView(tex1);
  
  
          nR1=(EditText)tex1.findViewById(R.id.R2);
          nC1=(EditText)tex1.findViewById(R.id.C2);
  
          alert1.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
  
              a3 = Integer.parseInt(nR1.getText().toString());
              b3 = Integer.parseInt(nC1.getText().toString());
              b2.setText(""+a3+"x"+b3);
  
              //multipleDimension(a1,b1,mat);
  
              final EditText ed1[][] = new EditText[a3][b3];  
              matrix2.removeAllViews();
              for (int i = 0; i &lt; a3; i++) {
              layout2 = new LinearLayout(
                      Dimensions.this);
  
              layout2.setOrientation(LinearLayout.HORIZONTAL);
  
              for (int j = 0; j &lt; b3; j++) {
  
                  ed1[i][j] = new EditText(Dimensions.this);
  
                  //ed[i][j].setId(+(i)+(j));
  
                  ed1[i][j].setLayoutParams(new LayoutParams(
                          LayoutParams.WRAP_CONTENT,
                          LayoutParams.WRAP_CONTENT));
                  ed1[i][j].setHint("a"+(i+1)+(j+1));
                  ed1[i][j].setTextColor(Color.RED);
  
  
  
                  layout2.addView(ed1[i][j]);
              }
  
              matrix2.addView(layout2);
  
              }
  
            }
          }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  dialog.dismiss();
              }
          }).show();
  
  
  
      break;
  }
      bmul.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              Intent intent=new Intent(Dimensions.this,ArithmaticOperation.class);
              String s[][]= new String[a1][b1];
              intent.putExtra("m", a1);
              intent.putExtra("n", b1);
              for (int i=0;i&lt;a1; i++){
                  for (int j=0;j&lt;a1; j++){
  
                      s[i][j]=**ed[i][j]**.getText().toString();
                      intent.putExtra("key["+i+"]["+j+"]",  s[i][j]);
  
                  }
  
              }
          }
      });
  }
  
  
  
  
          }
  </code></pre>
  
  <p>Here I instantiate the EditText Array</p>
  
  <pre><code>case R.id.button1:
  
         //creatDialog(matrix,submit);
          AlertDialog.Builder alert = new AlertDialog.Builder(this);
  
          LayoutInflater inflater = this.getLayoutInflater();
  
  
          alert.setTitle("Define Dimensions");
          alert.setMessage("Assign Numbers of Rows and Columns to Matrix");
  
          //Set an EditText view to get user input 
  
          final View tex =inflater.inflate(R.layout.dialog_dimension,null);
  
          alert.setView(tex);
  
  
          nR=(EditText)tex.findViewById(R.id.R2);
          nC=(EditText)tex.findViewById(R.id.C2);
  
          alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
  
              a1 = Integer.parseInt(nR.getText().toString());
              b1 = Integer.parseInt(nC.getText().toString());
              submit.setText(""+a1+"x"+b1);
  
              //multipleDimension(a1,b1,mat);
  
              **final EditText ed[][] = new EditText[a1][b1];**  
              matrix.removeAllViews();
              for (int i = 0; i &lt; a1; i++) {
              layout = new LinearLayout(
                      Dimensions.this);
  
              layout.setOrientation(LinearLayout.HORIZONTAL);
  
              for (int j = 0; j &lt; b1; j++) {
  
                  ed[i][j] = new EditText(Dimensions.this);
  
                  //ed[i][j].setId(+(i)+(j));
  
                  ed[i][j].setLayoutParams(new LayoutParams(
                          LayoutParams.WRAP_CONTENT,
                          LayoutParams.WRAP_CONTENT));
                  ed[i][j].setHint("a"+(i+1)+(j+1));
                  ed[i][j].setTextColor(Color.RED);
  
  
  
                  layout.addView(ed[i][j]);
              }
  
              matrix.addView(layout);
  
              }
  
  
            }
          }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  dialog.dismiss();
              }
          }).show();
  
  
      break;
  </code></pre>
  
  <p>and Here I got Error</p>
  
  <pre><code>bmul.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              Intent intent=new Intent(Dimensions.this,ArithmaticOperation.class);
              String s[][]= new String[a1][b1];
              intent.putExtra("m", a1);
              intent.putExtra("n", b1);
              for (int i=0;i&lt;a1; i++){
                  for (int j=0;j&lt;a1; j++){
  
                      s[i][j]=**ed[i][j]**.getText().toString();
                      intent.putExtra("key["+i+"]["+j+"]",  s[i][j]);
  
                  }
  
              }
          }
      });
  </code></pre>