package?com.webabcd.dialog;
import java.util.Calendar;
import?android.app.Activity;
import?android.app.AlertDialog;
import?android.app.DatePickerDialog;
import?android.app.Dialog;
import?android.app.ProgressDialog;
import?android.app.TimePickerDialog;
import?android.app.DatePickerDialog.OnDateSetListener;
import?android.app.TimePickerDialog.OnTimeSetListener;
import?android.content.DialogInterface;
import?android.content.DialogInterface.OnClickListener;
import?android.os.Bundle;
import?android.view.View;
import?android.widget.DatePicker;
import?android.widget.TextView;
import?android.widget.TimePicker;
import?android.widget.Button;
public?class?Main?extends?Activity?{
????/**?Called?when?the?activity?is?first?created. */
[email protected]
????public?void?onCreate(Bundle?savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.main);
????????//弹出式对话框的?Demo。先调用?Builder(),在?Create(),?需要显示对话框的是后再调用?show()
????????AlertDialog?dialog?=?new?AlertDialog.Builder(this).setTitle("弹出对话框").create();
????????dialog.show();
????????//以下是各种对话框的?Demo
????????MyButtonClickListener?listener?=?new?MyButtonClickListener();
????????Button?btn1?=?(Button)?this.findViewById(R.id.btn1);
????????btn1.setText("简单的对话框的?Demo");
????????btn1.setOnClickListener(listener);
????????Button?btn2?=?(Button)?this.findViewById(R.id.btn2);
????????btn2.setText("包括常用设置的对话框(数据来自?xml)");
????????btn2.setOnClickListener(listener);
????????Button?btn3?=?(Button)?this.findViewById(R.id.btn3);
????????btn3.setText("弹出的对话框的内容是一个?View");
????????btn3.setOnClickListener(listener);
????????Button?btn4?=?(Button)?this.findViewById(R.id.btn4);
????????btn4.setText("日期选择对话框");
????????btn4.setOnClickListener(listener);
????????Button?btn5?=?(Button)?this.findViewById(R.id.btn5);
????????btn5.setText("时间选择对话框");
????????btn5.setOnClickListener(listener);
????????Button?btn6?=?(Button)?this.findViewById(R.id.btn6);
????????btn6.setText("进度条对话框");
????????btn6.setOnClickListener(listener);
????}
????class?MyButtonClickListener?implements?View.OnClickListener?{
[email protected]
????????public?void?onClick(View?v) {
????????????
????????????//具体的对话框的实现可以通过重写?onCreateDialog?完成
????????????
????????????switch?(v.getId()) {
????????????case?R.id.btn1:
????????????????Main.this.showDialog(0);
????????????????break;
????????????case?R.id.btn2:
????????????????Main.this.showDialog(1);
????????????????break;
????????????case?R.id.btn3:
????????????????Main.this.showDialog(2);
????????????????break;
????????????case?R.id.btn4:
????????????????Main.this.showDialog(3);
????????????????break;
????????????case?R.id.btn5:
????????????????Main.this.showDialog(4);
????????????????break;
????????????case?R.id.btn6:
????????????????Main.this.showDialog(5);
????????????????break;
????????????}
????????}
????}
[email protected]
????public?Dialog?onCreateDialog(int?id) {
????????switch?(id) {
????????case?0:
????????????//一个简单的弹出对话框
????????????return?new?AlertDialog.Builder(this).setTitle("这是一个简单的弹出对话框的?Demo")
????????????????????.create();
????????case?1:
????????????//一个相对复杂的弹出对话框
????????????return?new?AlertDialog.Builder(this)
????????????????????.setTitle("标题")?//设置标题
????????????????????//.setCustomTitle(View)?//以一个?View?作为标题?
????????????????????.setIcon(R.drawable.icon01)?//设置标题图片
????????????????????//.setMessage("信息")?//需要显示的弹出内容
????????????????????.setPositiveButton("确定",?new?OnClickListener() {?//设置弹框的确认按钮所显示的文本,以及单击按钮后的响应行为
[email protected]
[email protected]lick(DialogInterface?a0,?int?a1) {
????????????????????????????TextView?txtMsg?=?(TextView)?Main.this.findViewById(R.id.txtMsg);
????????????????????????????txtMsg.append("单击了对话框上的“确认”按钮\n");
????????????????????????}
????????????????????})
????????????????????.setItems(R.array.ary,?new?DialogInterface.OnClickListener() {?//弹框所显示的内容来自一个数组。数组中的数据会一行一行地依次排列
????????????????????????public?void?onClick(DialogInterface?dialog,????int?which) {
????????????????????????}
????????????????????})
????????????????????//其他常用方法如下
????????????????????//.setMultiChoiceItems(arg0,?arg1,?arg2)
????????????????????//.setSingleChoiceItems(arg0,?arg1,?arg2)
????????????????????//.setNeutralButton(arg0,?arg1)
????????????????????//.setNegativeButton(arg0,?arg1)
????????????????????.create();
????????case?2:
????????????//弹出对话框为指定的?View?的?Demo
????????????return?new?AlertDialog.Builder(this).setTitle("此对话框的内容是一个?View")
????????????????????.setView(this.findViewById(R.layout.view)).create();
????????case?3:
????????????//弹出日期选择对话框
????????????Calendar?c?=?Calendar.getInstance();
????????????return?new?DatePickerDialog(this,?new?OnDateSetListener() {
[email protected]
????????????????public?void?onDateSet(DatePicker?view,?int?year,?int?monthOfYear,?int?dayOfMonth) {
????????????????????TextView?txtMsg?=?(TextView)?Main.this.findViewById(R.id.txtMsg);
????????????????????txtMsg.append("新设置的日期为:"?+?String.valueOf(year)?+?"-"
????????????????????????????+?String.valueOf(monthOfYear)?+?"-"
????????????????????????????+?String.valueOf(dayOfMonth)?+?"\n");
????????????????}
????????????},?c.get(Calendar.YEAR),?c.get(Calendar.MONTH),?c.get(Calendar.DATE));
????????case?4:
????????????//弹出时间选择对话框
????????????Calendar?c2?=?Calendar.getInstance();
????????????return?new?TimePickerDialog(this,?new?OnTimeSetListener() {
[email protected]
????????????????public?void?onTimeSet(TimePicker?view,?int?hourOfDay,?int?minute) {
????????????????????TextView?txtMsg?=?(TextView)?Main.this.findViewById(R.id.txtMsg);
????????????????????txtMsg.append("新设置的时间为:"?
????????????????????????????+?String.valueOf(hourOfDay)?+?":"
????????????????????????????+?String.valueOf(minute)?+?"\n");
????????????????}
????????????},?c2.get(Calendar.HOUR),?c2.get(Calendar.MINUTE),?true);
????????case?5:
????????????//弹出进度条对话框
????????????ProgressDialog?progress?=?new?ProgressDialog(this);
????????????progress.setMessage("loading...");
????????????return?progress;
????????default:
????????????return?null;
????????}
????}
}
详细解决方案
Android - 对话框(Dialog)跟通知(Notification)
热度:294 发布时间:2016-05-01 16:18:45.0
相关解决方案
- android 读取byte[]中的元素解决方案
- android 标题栏兑现方式
- android 中Activity向BroadcastReceiver发送数据,该怎么解决
- Android 4.0 为什么模拟器老是提示小弟我谷歌拼音输入法已停止
- android:getSharedPreferences() 这是哪个类的方法解决思路
- android 怎么判断一个程序是否联网
- android 大量数据按周分组,该如何解决
- android RadioButton如何设置默认选中
- ksoap2-android-这个包,连接webService怎么设置超时
- android 怎么重新设置锚点
- android UI界面设计解决方案
- android 图片对象获取的有关问题
- android 怎么调用淘宝支付宝接口
- Android 沿袭InputMethodService自定义输入法
- android 关于服务连接的疑义
- android 两个activity如何通信
- android 怎么实现对view的放大和缩小
- android 教程解决方法
- android ID,该如何处理
- 准备复习2-3个月,看java+android,请问有经验者,怎么看效果最好》
- android UI线程与AsyncTask的有关问题
- android(java)中的java.net能不能和c#的system.net.sockets进行tcp通信,该如何解决
- android ListView 中的onItemClick Intent 没法跳转
- android(java) 中文乱码的有关问题
- apple push notification 服务器设计有关问题?
- 使用Jquery.ui.Dialog 插件和jquery Ztree 2个插件 样式乱了解决思路
- c#c++,android,ios(iphone),php,java视屏课程 散分
- jquery ui dialog 有关问题(添加到form1里面后还是无法使用服务器控件)
- 使用art.dialog.load加载登陆页返回的有关问题
- android Post文件到ASP.NET的有关问题,能收到参数收不到文件