【发布时间】:2017-02-09 09:12:22
【问题描述】:
我正在测试 AlertDialog 的行为以集成到更大的组件中。我无法再次显示相同的对话框。下面是测试代码:
public class MainActivity extends AppCompatActivity {
private AlertDialog alertDialogACCreationRetry;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alertDialogACCreationRetry = new AlertDialog.Builder(this)
.setTitle("Account creation failed")
.setMessage("There was a problem connecting to the Network. Check your connection.")
.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create();
alertDialogACCreationRetry.show();
alertDialogACCreationRetry.show();
}
}
我尝试将alertDialogACCreationRetry.show(); 放在重试按钮中,但它仍然不会显示。我也尝试将alertDialogACCreationRetry.dismiss(); 放在重试按钮内,然后在外面调用alertDialogACCreationRetry.show();,它仍然没有显示。更可怕的是,如果不应该允许,它不会给我一个例外来重新显示它。
所以,我的问题是这样的:每次按下按钮后(自动)解除对话框后,我是否都必须创建一个新对话框?
【问题讨论】:
-
您可以尝试使用 Dialog。
-
是的,你会再创建一个新的对话实例@pulp_fiction
-
@АксеновВладимир :我可以覆盖正面按钮行为,但是当我调用 alertDialogACCreationRetry.show();稍后,即使没有按钮覆盖,它也应该重新显示对话框。
标签: android android-alertdialog