Android Dialogs(2)最好用DialogFragment创建Dialog
Creating a Dialog Fragment
You can accomplish a wide variety of dialog designs—including custom layouts and those described in theDialogs design guide—by extending DialogFragment and creating a AlertDialog in the onCreateDialog()callback method.
For example, here's a basic AlertDialog that's managed within a DialogFragment:
public class FireMissilesDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.dialog_fire_missiles)
.setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
Now, when you create an instance of this class and callshow() on that object, the dialog appears as shown in figure 1.

Figure 1. A dialog with a message and two action buttons.
The next section describes more about using theAlertDialog.Builder APIs to create the dialog.
Depending on how complex your dialog is, you can implement a variety of other callback methods in theDialogFragment, including all the basic fragment lifecycle methods.
Android Dialogs(2)最好用DialogFragment创建Dialog的更多相关文章
- Android控件大全(一)——DialogFragment创建对话框
DialogFragment在android 3.0时被引入.是一种特殊的Fragment,用于在Activity的内容之上展示一个模态的对话框.典型的用于:展示警告框,输入框,确认框等等. 在Dia ...
- DialogFragment创建默认dialog
代码地址如下:http://www.demodashi.com/demo/12228.html 记得把这几点描述好咯:代码实现过程 + 项目文件结构截图 + 演示效果 前言 在我们项目的进行中不可避免 ...
- Android 官方推荐 : DialogFragment 创建对话框
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37815413 1. 概述 DialogFragment在android 3.0时 ...
- [Android Pro] Android 官方推荐 : DialogFragment 创建对话框
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37815413 1. 概述 DialogFragment在android 3.0时 ...
- 转帖:Android 官方推荐 : DialogFragment 创建对话框
转: Android 官方推荐 : DialogFragment 创建对话框 复制内容,留作备份 1. 概述 DialogFragment在android 3.0时被引入.是一种特殊的Fragment ...
- 【转】 Pro Android学习笔记(四五):Dialog(2):DialogFragment
[-] 重写onCreateView 通过onCreateView设置UI和按键反馈 信息保存 重写onCreateDialog DialogFragment的实例newInstance()已经在上一 ...
- Android Dialogs(1)Dialog简介及Dialog分类
Dialogs A dialog is a small window that prompts the user to make a decision or enter additional info ...
- Android开发:使用DialogFragment实现dialog自定义布局
使用DialogFragment实现dialog的自定义布局最大的好处是可以更好控制dialog的生命周期. TestFragment的代码: public class TestFragment ex ...
- 使用DialogFragment创建对话框总结
回调Activity中的函数 http://developer.android.com/guide/topics/ui/dialogs.html#PassingEvents 在DialogFragme ...
随机推荐
- 相机标定(Camera calibration)
简单介绍 摄像机标定(Camera calibration)简单来说是从世界坐标系换到图像坐标系的过程.也就是求终于的投影矩阵 P 的过程,以下相关的部分主要參考UIUC的计算机视觉的课件(网址Spr ...
- 微信小程序-setData()方法
一般setData方法多用于点击后改变页面信息或者刷新后与后台交互获取最新的信息 注意: 直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致 ...
- ZOJ 2706 Thermal Death of the Universe (线段树)
题目链接:ZOJ 2706 Thermal Death of the Universe (线段树) 题意:n个数.m个操作. 每一个操作(a,b)表示(a,b)全部值更新为这个区间的平均数:1.当前的 ...
- asp.net mvc 抓取京东商城分类
555 asp.net mvc 抓取京东商城分类 URL:http://www.jd.com/allSort.aspx 效果: //后台代码 public ActionResult Get ...
- 如何将Python的py程序打包成跨平台的exe文件
在编写了自己的第一个可以爬写网页源代码的程序之后,发现如果在没有安装了pythonLDLE程序的计算机上根本就跑不出来.所以开始寻找可以将程序打包成跨平台运行的exe文件. 经过自己费力的谷歌没有一个 ...
- SPOJ QTREE6 lct
题目链接 岛娘出的题.还是比較easy的 #include <iostream> #include <fstream> #include <string> #inc ...
- iOS 开发小常识 开发笔记
一 自定义push方法 /* 参数说明 * controllerName : push的目标页 例:@“testcontroll” ---注意不带.h * isNibPage ...
- C语言细节笔记2
C语言常见问题笔记: 1. 指针的声明 char * p1, p2; p1 是一个指向char类型的指针,而p2是一个char类型变量 这是由于 * 并不是基本类型的一部分,而是包含 ...
- Linux Chromium安装Adobe Flash Player
首先,下载: install_flash_player_11_linux.i386.tar.gz 解压文件: tar -xvf install_flash_player_11_linux.i386.t ...
- Android TabHost设置setCurrentTab(index),当index!=0时,默认加载第一个tab问题解决方法。
最近在用TabHost,默认希望显示第2个tab,发现总是加载第三个tab的同时加载第一个,解决方法如下: 1.首先查看addTab(TabSpec tabSpec)源代码: /** * Add a ...