AlertDialog类的使用
2012-11-25 20:51
489 查看
创建对话框的时候,我们需要通过AlertDialog.Builder(Context context)生成器来构造一个Builder并生成一个AlertDialog。
下面创建含有OK和Cancel两个按钮的dialog对话框。
new AlertDialog.Builder(MyAlertDialog.this)
// MyAlertDialog.this视情况而定,这个一般是指当前显示的Activity对应的xml视窗。
.setTitle("真的要离开?")// 设置对话框的标题
.setMessage("你确定要离开")// 设置对话框的内容
.setPositiveButton("OK",// 设置对话框的确认按钮
new DialogInterface.OnClickListener() {// 设置确认按钮的事件
public void onClick(DialogInterface dialog, int which) {
// do something here..I end this Prograss..
android.os.Process.killProcess(android.os.Process.myPid());
}})
.setNegativeButton("Cancel",// 设置对话框的取消按钮
new DialogInterface.OnClickListener() {// 设置取消按钮的事件
public void onClick(DialogInterface dialog, int which) {
// 如果你什么操作都不做,可以选择不写入任何代码
dialog.cancel();
}}
).show();
一般的格式总结如下:
new AlertDialog.Builder(Context)
.setTitle()
.setMessage()
.setPositiveButton("OK",
new DialogInterface.OnClickListener(){
pulic void onClick(DialogInterface dialog, int which){
xxx //do something
}})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener(){
xxx //do something
}}).show()
下面创建含有OK和Cancel两个按钮的dialog对话框。
new AlertDialog.Builder(MyAlertDialog.this)
// MyAlertDialog.this视情况而定,这个一般是指当前显示的Activity对应的xml视窗。
.setTitle("真的要离开?")// 设置对话框的标题
.setMessage("你确定要离开")// 设置对话框的内容
.setPositiveButton("OK",// 设置对话框的确认按钮
new DialogInterface.OnClickListener() {// 设置确认按钮的事件
public void onClick(DialogInterface dialog, int which) {
// do something here..I end this Prograss..
android.os.Process.killProcess(android.os.Process.myPid());
}})
.setNegativeButton("Cancel",// 设置对话框的取消按钮
new DialogInterface.OnClickListener() {// 设置取消按钮的事件
public void onClick(DialogInterface dialog, int which) {
// 如果你什么操作都不做,可以选择不写入任何代码
dialog.cancel();
}}
).show();
一般的格式总结如下:
new AlertDialog.Builder(Context)
.setTitle()
.setMessage()
.setPositiveButton("OK",
new DialogInterface.OnClickListener(){
pulic void onClick(DialogInterface dialog, int which){
xxx //do something
}})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener(){
xxx //do something
}}).show()
相关文章推荐
- Android之使用AlertDialog类和AlertDialog.Builder类创建带取消,确定,中立的对话框
- 如何在iOS中使用Block──How to use Blocks with iOS
- C/C++ 直接使用动态库 dlopen
- Django中template 使用
- ubuntu12.04 使用Adobe Reader PDF
- vi/vim使用进阶: quickfix
- pt-online-schema-change 工具使用
- 在使用macbook pro过程中遇到 <此apple id尚未用于App Store>,解决方法!
- Linux关于GNUPLOT的使用技巧
- 15分钟学会使用Git和远程代码库
- NoSql数据库使用半年后在设计上面的一些心得
- SQL 使用经验
- grep和egrep的使用
- android详细的对话框AlertDialog.Builder使用方法
- 学习maven的使用,看到一篇很实用的入门教程(菜鸟级入门)
- Debian系统下winrar的安装与使用
- Intelij IDE 使用参考链接
- java中switch使用的数据类型
- 使用OpenCV编写的LDA程序----C++ LDA代码
- Android AIDL的使用