问题
I'm playing around with a simple Android game, and i want to restart my activity when my AlertDialog is appearing. But when i was try to use AlertDialog, any field outside AlertDialog has been disabled. Now i want to active my RestartButton. Here is my code:
if (myValue == result) {
case 1: //dosomething
} else {
new AlertDialog.Builder(context)
.setTitle("Wrong Result, plese try again")
.setMessage("Your Score/High Score : " + score +"/" + (String.valueOf(mPreferences.getInt("personalRecord", 0))))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
回答1:
AlertDialogs
are modal. This means that they take over the window and you have to address them before moving on. You could roll your own solution and just show a View
that doesn't block the rest of the screen or you could add a button to the AlertDialog
that performs the same function as the button under it that you want users to be able to hit.
来源:https://stackoverflow.com/questions/38268298/how-to-enable-button-when-alertdialog-has-activated