如何启用按钮时,AlertDialog已经启动? [英] How to enable Button when AlertDialog has activated?
问题描述
我用一个简单的Android游戏玩耍,我要当我的AlertDialog正在出现重新启动我的活动。但是,当我尝试使用AlertDialog,AlertDialog以外的领域已被禁用。现在,我想我的活跃RestartButton。这里是我的code:
如果(myvalue的==结果){
案例1:// DoSomething的
}其他{
新AlertDialog.Builder(上下文)
.setTitle(错误结果,普莱舍再试一次。)
.setMessage(你的分数/高分:+分+/+(将String.valueOf(M preferences.getInt(personalRecord,0))))
.setPositiveButton(android.R.string.ok,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话,诠释它){
//继续删除
}
})
.setNegativeButton(android.R.string.no,新DialogInterface.OnClickListener(){
公共无效的onClick(DialogInterface对话,诠释它){
// 没做什么
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
。显示();
}
AlertDialogs
是模态。这意味着,他们接管窗口,你必须在移动之前解决这些问题。你可以滚你自己的解决方案,只是显示查看
不阻止屏幕的其余部分,或者你可以添加一个按钮 AlertDialog
执行同样的功能,你希望用户能够击中它下面的按钮。
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();
}
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.
这篇关于如何启用按钮时,AlertDialog已经启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!