When I want to retrieve a value from an Alert box in android, it returns before I click on OK button.

here is the function I made:

```
public String enterSecretCode(){

    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Secret Code");
    alert.setMessage("Enter your 5 digit Secret Code to Encode!");

 // Set an EditText view to get user input
    final EditText input = new EditText(this);
    input.setFilters(new InputFilter[] {new InputFilter.LengthFilter(5)});
    input.setHint("XXXXX");
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            code = input.getText().toString();
            // Do something with value!
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
        }
    });

    alert.show();

    return code;
}

```

and here is the function call which I am trying to excuse on a button click:

```
String secretCode = enterSecretCode();

```