安卓:警告对话框,取消按钮 [英] Android :Alert Dialog, Cancel Button

查看:270
本文介绍了安卓:警告对话框,取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有五个对话框 CheckedTextView 。当我打开对话框,点击一些复选框并比我点击取消按钮。但是,当我再次打开对话框。所做的更改将被保存。为什么?如何取消我的点击,当我preSS取消按钮?

I have a dialog with five CheckedTextView. When I open dialog and Click on some CheckBoxes and than I click Cancel Button. But when I open dialog again. The changes made is saved. Why? How to cancel what I clicked when I press Cancel button ?

推荐答案

Android的创建对话框中只有一次,然后重新使用它,而不是重新创建的。因此,你的 onCreateDialog 方法被调用一次。第二次,你会得到同样的对话框,在同一个国家同一个复选框。

Android creates the dialog box just once, and then reuses it instead of recreating it. Thus, your onCreateDialog method is called only once. The second time, you get the same dialog, with the same check boxes in the same state.

要确保对话框包含正确的数据,重写<一个href=\"http://developer.android.com/reference/android/app/Activity.html#on$p$ppareDialog%28int,%20android.app.Dialog%29\"相对=nofollow> 上prepareDialog 。这被调用的每个的显示在对话框右侧前的时间。从这里,你可以设置复选框为所需的状态。

To ensure that the dialog contains the correct data, override onPrepareDialog. This gets called every time right before the dialog is shown. From here, you can set the check boxes to the desired state.

这篇关于安卓:警告对话框,取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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