title: How to use the AlertDialog's return value
body: <p>In mostly situation, I need the user to make a choice many times.( I do something and raise a message box for the user to make a choice and continue do other thing(maybe called block))
  So I wrote a common function </p>
  
  <pre><code>public static void ShowMsgDialog(Context self,String title, String msg)
  </code></pre>
  
  <p>Although it correctly response the user’s action, but always pending (that means while I click the button, the previous action's value is visible by global variable’s value) 
  Is there exist any function which I could got the message box's return value and use it like this:</p>
  
  <pre><code>int ret = ShowMsgDialog(Context self,String title, String msg);
  </code></pre>
  
  <p>the follow is my code:</p>
  
  <pre><code>public class MainActivity extends Activity {
      private Button button1;
      enum Answer { YES, NO, ERROR};
      static Answer choice;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);     
          button1 = (Button)findViewById(R.id.button1);
  
          button1.setOnClickListener(new OnClickListener() {          
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  ShowMsgDialog(MainActivity.this, "Information", "you choice? "); 
                  if(choice == Answer.YES)
                      Toast.makeText(MainActivity.this, "YOU CHOICED YES", Toast.LENGTH_LONG).show();
                  else if (choice == Answer.NO)
                      Toast.makeText(MainActivity.this, "YOU CHOICED NO", Toast.LENGTH_LONG).show();
                  else
                      Toast.makeText(MainActivity.this, "ERROR OCUS", Toast.LENGTH_LONG).show();
  
                  //int ret = ShowMsgDialog(MainActivity.this, "Information", "you choice? ");  
              }
          });     
      }
  
      public static void ShowMsgDialog(Context self,String title, String Msg){
          AlertDialog.Builder dlgAlert = new AlertDialog.Builder(self);
          dlgAlert.setTitle(title);
          dlgAlert.setMessage(Msg);
          dlgAlert.setPositiveButton("OK",new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                  // call your code here
                  choice = Answer.YES;
              }
          });
          dlgAlert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  // TODO Auto-generated method stub
                  choice = Answer.NO;
              }
          });
          dlgAlert.show();
      }
  
  
  
  }
  </code></pre>