import java.util.Calendar;
import android.widget.DatePicker;
import android.app.DatePickerDialog; //日期对话框的标记 常量
private static final int DATE_DIALOG_ID = 1;
private static final int SHOW_DATAPICK = 0;
//日期变量
private int mYear;
private int mMonth;
private int mDay;
//当前操作的日期控件的标记
private String strDate_Tag=""; //购买日期
private EditText m_txtPurchaseDate = null;
private Button m_butPurchaseDate = null;
//安装日期
private EditText m_txtInstallationDate = null;
private Button m_butInstallationDate = null; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //购买日期
m_txtPurchaseDate = (EditText) findViewById(R.id.txtPurchaseDate);
m_butPurchaseDate = (Button) findViewById(R.id.butPurchaseDate);
//安装日期
m_txtInstallationDate= (EditText) findViewById(R.id.txtInstallationDate);
m_butInstallationDate = (Button) findViewById(R.id.butInstallationDate); initDate();//初始化 日期
} //初始化 日期
private void initDate(){ final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
//setDateTime();//设置日期
strDate_Tag="PurchaseDate";//购买日期
setDateTime();
strDate_Tag="InstallationDate";//安装日期
setDateTime();
}
//设置日期 为文本框 赋值
private void setDateTime() {
if(strDate_Tag=="PurchaseDate"){//购买日期
m_txtPurchaseDate.setText(new StringBuilder().append(mYear +"-").append(
(mMonth + 1) < 10 ? "0" + (mMonth + 1)+"-" : (mMonth + 1)+"-").append(
(mDay < 10) ? "0" + mDay : mDay));
}else if(strDate_Tag=="InstallationDate"){//安装日期
m_txtInstallationDate.setText(new StringBuilder().append(mYear +"-").append(
(mMonth + 1) < 10 ? "0" + (mMonth + 1)+"-" : (mMonth + 1)+"-").append(
(mDay < 10) ? "0" + mDay : mDay));
}
} //日期控件的事件
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
setDateTime(); //设置日期 为文本框 赋值
}
}; //购买日期Button的事件处理
class butPurchaseDateOnClickListener implements
android.view.View.OnClickListener {
public void onClick(View v) {
strDate_Tag="PurchaseDate";//当前点击的日期为 购买日期 String[] arrPurchaseDate =m_txtPurchaseDate.getText().toString().split("-");
mYear = Integer.parseInt(arrPurchaseDate[0]);
mMonth = Integer.parseInt(arrPurchaseDate[1]);
mDay = Integer.parseInt(arrPurchaseDate[2]); Message msg = new Message();
if (m_butPurchaseDate.equals((Button) v)) {
msg.what = MainActivity.SHOW_DATAPICK;
}
MainActivity.this.saleHandler.sendMessage(msg);
}
}
//购买日期Button的事件处理
class butInstallationDateOnClickListener implements
android.view.View.OnClickListener {
public void onClick(View v) {
strDate_Tag="InstallationDate";//当前点击的日期为 安装日期 String[] arrInstallationDate =m_txtInstallationDate.getText().toString().split("-");
mYear = Integer.parseInt(arrInstallationDate[0]);
mMonth = Integer.parseInt(arrInstallationDate[1]);
mDay = Integer.parseInt(arrInstallationDate[2]); Message msg = new Message();
if (m_butInstallationDate.equals((Button) v)) {
msg.what = MainActivity.SHOW_DATAPICK;
}
MainActivity.this.saleHandler.sendMessage(msg);
}
} //创建对话框 日期
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID: //日期
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
}
return null;
} protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
break;
}
} //处理日期控件的Handler
Handler saleHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MainActivity.SHOW_DATAPICK:
showDialog(DATE_DIALOG_ID);
break;
}
}
};

Android 中日期对话框的应用的更多相关文章

  1. 9.Android之日期对话框DatePicker控件学习

    设置日期对话框在手机经常用到,今天来学习下. 首先设置好布局文件:如图 xml对应代码 <?xml version="1.0" encoding="utf-8&qu ...

  2. Android中的对话框AlertDialog使用技巧合集-转载

    Android中的对话框AlertDialog使用技巧合集     文章来自:http://blog.csdn.net/blue6626/article/details/6641105   今天我用自 ...

  3. Android中Dialog对话框的调用及监听

    Android中经常会需要在Android界面上弹出一些对话框提示用户,比如App的退出的时候都会有各种框来挽留你的心,支付宝的时候输入密码的密码框,非常常见及其实用的功能,类似于JS中的alter, ...

  4. Android中Dialog对话框

    布局文件xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...

  5. android中常见对话框之一AlertDialog

    在Android应用中,有多种对话框:Dialog.AlertDialog.ProgressDialog.时间.日期等对话框. (1)Dialog类,是一切对话框的基类,需要注意的是,Dialog类虽 ...

  6. android中提示&对话框----ProgressDialog&DatePickerDialog &TimePickerDialog&PopupWindow

    ProgressDialog(精度条对话框): 1.直接调用ProgressDialog提供的静态方法show()显示 2.创建ProgressDialog,再设置对话框的参数,最后show()出来 ...

  7. $Android中日期和时间选择器的实现

    创建日期或时间选择窗口需要弹出Dialog的时候,Activity类的showDialog方法已经弃用了,而推荐使用的是DialogFragment,本文总结一下其具体用法. (一)日期选择器 1.创 ...

  8. java android中日期时间 问题总结

    Date 类型: Date date = new Date();   // 代表获取当前系统日期和时间 System.out.println(date); 使用类的方法设置时间和日期:(通过该方法初始 ...

  9. android中提示&对话框----Notification

    Notification(状态栏通知) 一.Notification用于状态栏显示通知的控件,在不同的设备上面Notification是不一样的 二.Notification的基本布局 元素组成: I ...

随机推荐

  1. 第一章 Java常用的并发类

    注:本系列博客主要参考于<分布式Java应用:基础与实践>,林昊 著 1.常用的并发集合类 ConcurrentHashMap:线程安全的HashMap的实现 CopyOnWriteArr ...

  2. linux C 多线程/线程池编程 同步实例

    在多线程.线程池编程中经常会遇到同步的问题. 1.创建线程 函数原型:int pthread_create(pthread_t *thread, const pthread_attr_t *attr, ...

  3. [转] SSH免密码登陆以及穿越跳板机

    原文链接:http://www.cnblogs.com/lucantang/p/3315329.html SSH免密码登陆以及穿越跳板机   1. 免密码直连  [user@hostA ~] $ssh ...

  4. Lessons learned developing a practical large scale machine learning system

    原文:http://googleresearch.blogspot.jp/2010/04/lessons-learned-developing-practical.html Lessons learn ...

  5. Inf2Cat应用的参数使用详细介绍

    http://msdn.microsoft.com/zh-cn/subscriptions/ff547089   Inf2Cat Inf2Cat (Inf2Cat.exe) 是一个命令行工具,该工具确 ...

  6. Java HashMap 默认排序

    先看一段Java代码. package com.m58.test; import java.text.ParseException; import java.text.SimpleDateFormat ...

  7. hadoop2.2.0_hbase0.96_zookeeper3.4.5全分布式安装文档下载

    本文档主要内容有: 1.hadoop 2.2.0 集群安装与部署 2.HBase 0.96 集群安装与部署 3.Zookeeper 3.4.5集群安装部署 备注:安装文档可能有所遗漏,后续将持续更新. ...

  8. 经典,HTML5游戏,超级玛丽

    在线演示 在线演示 本地下载 这是一款使用HTML5开发的超级玛丽,有没有点儿时的记忆?长按向上键,可以跳的更高哦.如果你也喜欢可以当成休闲游戏,如果你是开发者,不防下载下来看看是如何生成的.

  9. 在MyEclipse中配置Weblogic10服务器

    MyEclipse中配置Weblogic10服务器 在MyEclipse中配置Weblogic10服务器也是很简单,现在将过程分享给有需要的人. 1.在下方的Server选项卡中,鼠标右键选择“Con ...

  10. php之快速入门学习-4(数据类型)

    PHP 5 数据类型 String(字符串), Integer(整型), Float(浮点型), Boolean(布尔型), Array(数组), Object(对象), NULL(空值). PHP ...