The function below returns a password entered in AlertDialog
and is in a class responsible for creating any dialog box in my app, but like all AlertDialog
the app does not "wait" for the function return to continue execution. My question is: how to make the app wait for the function return to continue running the rest of the code?
public String pass() {
final String[] result = new String[1];
final EditText txtUrl = new EditText(activity);
// Set the default text to a link of the Queen
txtUrl.setHint("digite a senha");
new AlertDialog.Builder(activity)
.setTitle("Senha")
.setMessage("Digite a senha para liberar o acesso")
.setView(txtUrl)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
result[0] = txtUrl.getText().toString();
}
})
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
return result[0];
}