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

查看:408
本文介绍了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) {

    ....

这是为什么?

Why is that?

推荐答案

只是设计一个新的XML布局你的对话框,并创建一个新的活动,并设置它的主题@android:款式/ 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>

在对话框中,单击听者code启动活性

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天全站免登陆