Android 嵌套的 AlertDialog - 这可能吗?

标签 android nested android-alertdialog

在我对数据库做一些不可逆的事情之前,我试图要求用户确认两次。问题是外部点击处理程序不等待内部点击处理程序。在第一个对话框上单击"is"按钮后,会短暂显示第二个对话框,但外部处理程序仍然会执行并完成,最终会销毁两个对话框。

new AlertDialog.Builder(ActivityMain.this).setMessage(
  "Are you sure?").setPositiveButton("Yes",
    new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface arg0, int arg1) {

    new AlertDialog.Builder(ActivityMain.this).setMessage(
      "Are you really sure?").setPositiveButton("Yes",
    new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface arg0, int arg1) {

    ....

这是为什么?

最佳答案

只需设计一个新的 xml 布局作为您的对话框并创建一个新 Activity 并将其主题设置为 @android:style/Theme.Dialog 在 Activity 标签下的 list 文件中:

<activity android:theme="@android:style/Theme.Dialog" android:name="LocationDialog"> </activity>

在对话框中点击监听器代码启动 Activity 为

new AlertDialog.Builder(ActivityMain.this).setMessage(
  "Are you sure?").setPositiveButton("Yes",
    new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface arg0, int arg1) {
             Intent i = new Intent(YourActivity.this, NewActivity.class);
             startActivity(i);
      }

这将以对话框的形式启动您的新 Activity ,您可以在其中轻松应用您的操作。

关于Android 嵌套的 AlertDialog - 这可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4415478/

相关文章:

android - 当我的应用程序进入后台时以编程方式从任务列表中删除我的应用程序(API <= 20)

android - 将毫米转换为像素

c# - 主对象和嵌套对象中的Elastic Search 2.0搜索查询

java - popup-AlertDialog 错误地出现在其他 fragment 中

android - 如何从具有 singleInstance 启动模式的 Activity 中正确启动语音识别 Activity ?

几秒钟后,Android 蓝牙 SPP 连接似乎断开了

java - 避免在android中使用非常量表达式

c++ - 嵌套模板 typedef - 类型定义

scala - 如何在 Play 2 模板中访问嵌套模型的属性

android - 无法从警报对话框中的 EditText View 获取数据