Android_Dialog cancle 和dismiss 区别
AlertDialog使用很方便,但是有一个问题就是:dismiss方法和cancel方法到底有什么不同?
AlertDialog继承与Dialog,现在各位看看结构图:

然后在Dialog类中找到了dismiss和cancel方法的实现。重要看dismiss的源码:
- public void cancel() {
- if (mCancelMessage != null) {
- // Obtain a new message so this dialog can be re-used
- Message.obtain(mCancelMessage).sendToTarget();
- }
- dismiss();
- }
看明白了吧! 在cancel方法中调用了dismiss方法。 但是现在还有一个问题就是:mCancelMessage是什么?
private Message mCancelMessage; // 这是源码中的声明
然后再来看源码:
- public void setOnCancelListener(final OnCancelListener listener) {
- if (listener != null) {
- mCancelMessage = mListenersHandler.obtainMessage(CANCEL, listener);
- } else {
- mCancelMessage = null;
- }
- }
- ublic void setCancelMessage(final Message msg) {
- mCancelMessage = msg;
- }
现在问题清楚了,就是如果你在创建AlertDialog的时候调用了setOnCancelListener 这个mCancelMessage变量有作用,否则dismiss和cancel等同。
Public void cancel ()
Cancel the dialog. This is essentially the same as calling dismiss(), but it will also call yourDialogInterface.OnCancelListener (if registered).
取消对话框,基本上和调用dismiss效果一样。但是cancel同事也会调用DialogInterface.OnCancelListener注册的事件,如果注册了。
public void dismiss ()
Dismiss this dialog, removing it from the screen. This method can be invoked safely from any thread. Note that you should not override this method to do cleanup when the dialog is dismissed, instead implement that inonStop().
参考:http://blog.csdn.net/cpcpc/article/details/6774823
Android_Dialog cancle 和dismiss 区别的更多相关文章
- android码农神器 偷懒工具 android懒人框架 LoonAndroid 3 讲解
LoonAndroid 3.0 Loonandroid是一个注解框架,不涉及任何UI效果,目的是一个功能一个方法,以方法为最小颗粒度对功能进行拆解.把功能傻瓜化,简单化,去掉重复性的代码,隐藏复杂的实 ...
- Android开发——diglog cancel与dismiss方法区别
AlertDialog dismiss 和 cancel方法的区别 AlertDialog使用很方便,但是有一个问题就是:dismiss方法和cancel方法到底有什么不同? 今天有时间,看了看源 ...
- Android对话框之dismiss和cancel和hide区别
在我们看来两者效果都是一样的,其实看下源码就知道cancel肯定会去调dismiss的,如果调用的cancel的话就可以监听DialogInterface.OnCancelListener. /** ...
- AlertDialog dismiss 和 cancel方法的区别
AlertDialog使用很方便,但是有一个问题就是:dismiss方法和cancel方法到底有什么不同? AlertDialog继承与Dialog,现在各位看看结构图: 然后在Dialog类中找到了 ...
- Android 开发 对话框Dialog dismiss和hide方法的区别
http://ningtukun.blog.163.com/blog/static/186541445201310151539697/ dismiss和hide方法都可以隐藏对话框,在需要的时候也可以 ...
- Dialog , ProgressDialog , PopWindow 区别
本质区别: Dialog:非阻塞对话框,弹出对话框时时,后台还可以做事情,点击背景时,对话框消失 ProgressDialog:带有圆形进度或者条形进度的对话框,一般结合handler使用.任务完成后 ...
- Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom
一.视图切换类型介绍 在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的. 在iphone中,segue有:push,modal,和cus ...
- Storyboard里面的几种Segue区别和视图的切换
几种segue:push.modal.popover.replace.cutom. 一.视图切换类型介绍 1.在iPhone和iPad中,segue的类型是不同的. 2.在iPhone中,segue有 ...
- initWithFrame、initWithCoder、awakeFromNib的区别和调用次序 & UIViewController生命周期 查缺补漏
当我们创建或者自定义一个UI控件时,就很可能会调用awakeFromNib.initWithCoder .initWithFrame这些方法.三者的具体区别如下: initWithFrame: 通过代 ...
随机推荐
- differ比较两个字符串的差异
"abcde","abdefk" ---->-c,+f,+k "aba","aababb" -----&g ...
- oracle取分组的前N条数据
select * from(select animal,age,id, row_number()over(partition by animal order by age desc) row_num ...
- Sql中的Exists和in
最近学习数据库的分页算法,提到第一种 SELECT TOP 页大小 *FROM table1WHERE id NOT IN ( SELECT TOP 页大小*(页数 ...
- PHP基础之 file_get_contents() 函数
定义和用法 file_get_contents() 函数把整个文件读入一个字符串中. 和 file() 一样,不同的是 file_get_contents() 把文件读入一个字符串. file_get ...
- commands - `tar`
remove files after pack: tar --remove-files -cf all.tar * compression: -j: bzip2 -z: gzip add file t ...
- 表单验证的validate.js插件---jQuery Validation Plugin
早上在公交车上看了一个关于慕课网的教程<表单验证的validate.js插件---jQuery Validation Plugin>,正好可以用到自己近期开发简易微博的注册页面和登录页面, ...
- python-整理-面向对象
python的类和perl的类有相似之处,类的方法的第一个参数是表示类的对象自己,相当于c#的this python中定义类 class person: ''示例类,人'' count=0; def ...
- #event.initMouseEvent
initMouseEvent 方法用于初始化通过 DocumentEvent 接口创建的 MouseEvent 的值.此方法只能在通过 dispatchEvent 方法指派 MouseEvent 之前 ...
- android 图片合成
package com.ebensz.eink.demo; import java.io.File; import java.io.FileOutputStream; import android.a ...
- Exception和IOException之间的使用区别
Exception和IOException之间的使用区别 先看一段代码.这段代码来自<深入剖析tomcat> public void await() { // 创建ServerSock ...