Android 嵌套 AlertDialog - 这可能吗? [英] Android nested AlertDialog - is this possible?

查看:28
本文介绍了Android 嵌套 AlertDialog - 这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to ask the user for confirmation twice before I do something irreversible to the database. The problem is that the outer click handler does not wait for the inner click handler. Once the Yes button is clicked on the first dialog, the 2nd dialog is displayed briefly, but the outer handler executes and completes nonetheless, ultimately destroying both dialogs.

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) {

    ....

这是为什么?

推荐答案

Just Design a new xml layout as your dialog 并创建一个新活动并将其主题设置为@android:style/Theme.Dialog 在清单文件下活动标签例如:

Just Design a new xml layout as your dialog and create a new activity and set it's theme to @android:style/Theme.Dialog in the manifest file under the activity tag ex:

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

在对话框中单击侦听器代码以

in the Dialog click listener code start the activity as

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);
      }

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

This will start your new activity as a dialog where you can apply your action easily.

这篇关于Android 嵌套 AlertDialog - 这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆