How to enable Button when AlertDialog has activated?

烈酒焚心 提交于 2019-12-13 08:27:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!