title: How can i use a variable in onClickListener of two buttons?
body: <p>I want to use a variable in two OnClickListener of two buttons.
  I am trying to register a user by verifying his mobile no by a verification code. I want to use this code in OnClickListener of "Verify" button to display a Dilog BoX.
  How can I use this integer variable "verificationCode" in these OnClickListeners.
  Following is my code</p>
  
  <pre><code>package com.deavnet.schoolapp;
  
  import com.deavnet.schoolapp.R;
  import com.deavnet.schoolapp.R.layout;
  import com.deavnet.schoolapp.R.menu;
  import android.app.AlertDialog;
  import android.content.DialogInterface;
  import android.R.string;
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.telephony.SmsManager;
  import java.util.Random;
  
  
  
  public class Verify extends Activity {
  
      final int verificationCode=0;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.verify_activity);
  
          // get the References of views
          final  EditText editTextMobileNo =(EditText)findViewById(R.id.editTextMobileNo);
          final EditText editConfirmMobileNo=(EditText)findViewById(R.id.editTextConfirmMobileNo);
          final Button btnSend=(Button)findViewById(R.id.buttonSend);
          final EditText editTextVerificationCode=(EditText)findViewById(R.id.editTextVerificationCode);
          final Button btnVerify=(Button)findViewById(R.id.buttonVerify);
  
  
          btnSend.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  String mbno=editTextMobileNo.getText().toString();
                  String confirmMbno=editConfirmMobileNo.getText().toString();
                  String enteredCode=editTextVerificationCode.getText().toString();
                  int verificationCodeEntered= Integer.parseInt(enteredCode);
  
  
                  if(mbno.equals(""))
                  {
                          Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show();
                          return;
                  }
                  else if(mbno!=confirmMbno)
                  {
                      Toast.makeText(getApplicationContext(), "Mobile Number do not match", Toast.LENGTH_LONG).show();
                      return;
                  }
                  else
                  {
                      int min = 1000;
                      int max = 9999;
                      Random r = new Random();
                      int i1 = r.nextInt(max - min + 1) + min;
  
                      int verificationCode = sendSMS(mbno,i1);
                  }
              }
          });
  
          btnVerify.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  String enteredCode=editTextVerificationCode.getText().toString();
                  int verificationCodeEntered= Integer.parseInt(enteredCode);
                  dilogfun(verificationCodeEntered);
              }
          });
      }
      public int sendSMS(String mbno, int code) {
  
          try{
  
          SmsManager smsManager = SmsManager.getDefault();
          smsManager.sendTextMessage(mbno, null,""+code+"" , null, null);
          }
          catch(Exception e){
              Log.d("msg error", ""+e.getMessage());
              e.printStackTrace();
          }
          Toast.makeText(getApplicationContext(), "Message Sent!", Toast.LENGTH_LONG).show();
          return code;
      }
  
      public boolean dilogfun(int verificationCodeEntered)
      {
          if(verificationCode==verificationCodeEntered)
          {
              // Creating alert Dialog with one Button
  
              AlertDialog alertDialog = new AlertDialog.Builder(
                      Verify.this).create();
  
              // Setting Dialog Title
              alertDialog.setTitle("Regestration");
  
              // Setting Dialog Message
              alertDialog.setMessage("Congratcs... Registration Successfull...");
  
              // Setting Icon to Dialog
              alertDialog.setIcon(R.drawable.tick);
  
              // Setting OK Button
              alertDialog.setButton("OK",
                      new DialogInterface.OnClickListener() {
  
                          public void onClick(DialogInterface dialog,
                                  int which) {
                              // Write your code here to execute after dialog
                              // closed
                              Toast.makeText(getApplicationContext(),
                                      "Thank You...", Toast.LENGTH_SHORT)
                                      .show();
                          }
                      });
  
              // Showing Alert Message
              alertDialog.show();
          } 
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.login_activity, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>Hoping for best results...
  Thank you</p>