Android之对话框
来源:互联网 发布:男士香水品牌 知乎 编辑:程序博客网 时间:2024/06/04 19:33
注:本文只是一个学习笔记 用以记录自己学到哪了
1.获得AlertDialog的静态内部类Builder对象,由此类来创建对话框
2.通过Builder对象设置对话框的标题 按钮以及按钮响应的事件
3.调用Builder的Create()方法创建对话框
4.调用AlertDialog的show()方法显示对话框
main.xml文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextView android:id="@+id/MyTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /><Button android:id="@+id/myButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="创建Alert对话框" /></LinearLayout>MainActivity文件
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myTextView = (TextView)findViewById(R.id.MyTextView); myButton = (Button)findViewById(R.id.myButton); //添加AlertDialog.Builder对象 final AlertDialog.Builder builder = new AlertDialog.Builder(this); //为activity中按钮添加按钮事件 myButton.setOnClickListener(new View.OnClickListener(){@Overridepublic void onClick(View v){builder.setTitle("您确定要删除此条信息?").//设置确定按钮setPositiveButton("Yes", new OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which){myTextView.setText("删除成功");}}).//设置取消按钮setNegativeButton("No", new OnClickListener(){@Overridepublic void onClick(DialogInterface dialog, int which){myTextView.setText("取消删除");}}); //创建对话框 AlertDialog alertDialog = builder.create(); //显示对话框 alertDialog.show();}}); } }
- Android 控件之对话框
- Android 之对话框
- Android 之对话框 2
- Android之对话框
- Android对话框之AlertDialog
- 【Android】之【对话框 Dialog】
- Android之列表对话框
- 【Android】对话框之进度条
- Android之对话框Dialog
- Android之自定义对话框
- android之对话框
- Android编程之对话框
- Android开发之对话框
- Android之创建对话框
- android之对话框<一>
- android 之对话框
- Android知识点之对话框
- android之AlertDialog对话框
- PKU ACM 1011 Sticks
- 推荐两个C库
- c++ 与java中的堆栈,变量存储
- What's the meaning of EOF ?
- 让某些文件不受版本控制管理
- Android之对话框
- Microsoft Office Outlook 2007 签名中插入图片
- 读取xml文件,快速入门
- poj 1830(高斯消元求解。。。。)
- DOS下编译执行java程序
- 如何让网站被百度快速收录
- HDU 3944 组合数学+数论
- VM虚拟机 fedora 9 配置tftp服务
- 清华大学计算机系课程全套视频教程下载地址