App expect response from AlertDialog for password [duplicate]

1

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];
}
    
asked by anonymous 15.09.2016 / 14:57

1 answer

0

What if you call the next function only when the user gives OK?

Example:

.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    result[0] = txtUrl.getText().toString();
                    activity.someFunction();

                }
            })
    
15.09.2016 / 15:06