1,调用showDialog(int id)方法
2,重写onCreateDialog(int id, Bundle arges)方法,传入相应参数,new一个DatePickerDialog对象.
3,实现onDateSetListener接口,并new一个该实现类的对象
4,重写onDateSetListener中的onDateSet()方法
具体代码如下:
package com.sun.datepicker;
import com.sun.datetimepicker.R;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
public class DatePickerTestActivity extends Activity {
/** Called when the activity is first created. */
Button testDatePicker = null;
DatePickerDialog datePickerDialog = null;
static final int SHOW_DATE_PICKER_DIALOG = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testDatePicker = (Button)findViewById(R.id.testDatePicker);
testDatePicker.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(SHOW_DATE_PICKER_DIALOG);
}
});
}
DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
System.out.println(year+"year "+(monthOfYear+1)+"month "+dayOfMonth+"day");
}
};
protected Dialog onCreateDialog(int id, Bundle args) {
// TODO Auto-generated method stub
if(id == SHOW_DATE_PICKER_DIALOG){
return new DatePickerDialog(this, onDateSetListener, 2012, 1, 6);
}
return null;
}
}
分享到:
相关推荐
本文实例讲述了Android DatePicker和DatePickerDialog基本用法。分享给大家供大家参考,具体如下: DatePicker用来设置手机的时间和闹钟 1、添加一个按钮控件在配置文件中,然后给该按钮添加事件,使其能够打开...
主要介绍了Android 中NumberPicker,DatePicker与DatePickerDialog中分割颜色的修改实例代码的相关资料,这里提供实例代码,需要的朋友可以参考下
Android当中DatePickerDialog的使用
用AndroidWheel自定义DatePicker及DatePickerDialog,详细介绍见博客
使用DatePicker实现日历选择器及使用TimePicker实现时间选择器;使用DatePickerDialog实现日期选择对话框及使用TimePickerDialog实现时间选择对话框。
NULL 博文链接:https://flyer0126.iteye.com/blog/743449
自定义DatePickerDialog的实现
自定义的DatePickerDialog,实现DatePicker样式的自定义,Dialog的自定义
1.增加Theme主题 new DatePickerDialog(this, AlertDialog.THEME_HOLO_LIGHT,null).show(); 效果: ...DatePickerDialog datePicker = new DatePickerDialog(MainActivity.this, AlertDialog.THE
对于DatePicker的时间控件做出部分控制,记录下来,供以后快速使用。
android之date,日期与时间的简单编程,使用类DatePicker和DatePickerDialog和TimePicker和TimePickDialog
对DatePickerDialog时间选择器的集中简单的使用,和MVPPlugin开发插件的使用
android 动态输入日期与时间 DatePicker与TimePicker应用DatePickerDialog\TimePickerDialog
自定义选择年月的 DatePickerDialog,android 7.0系统也试用,不受系统版本限制
筒子们在使用bootstrap的日期控件(datepicker , 现在官网提供的名称叫 datetimepicker)时可能会遇到如上图的问题这是啥原因造成的呢? 答案很简单时输出的优先级造成的(z-index) z-index 的值越大优先级越高 就...
NULL 博文链接:https://zigtang.iteye.com/blog/1752018
演示Android下如何使用DatePicker和DatePickerDialog。