自定义时间弹出框,并限制最大时间和最小时间

private Dialog CreateDialog() {
// TODO Auto-generated method stub
MyDatePickerDialog dialog = null;
c = Calendar.getInstance();
dialog = new MyDatePickerDialog(this,
new DatePickerDialog.OnDateSetListener() {


@Override
public void onDateSet(DatePicker arg0, int arg1, int arg2,
int arg3) {

// TODO Auto-generated method stub

//选择时间后,跳入另外一个activity

intent = new Intent(context, MapActivity.class);

startActivity(intent);

// finish();
}
}, c.get(Calendar.YEAR), // 传入年份
c.get(Calendar.MONTH), // 传入月份
c.get(Calendar.DAY_OF_MONTH) // 传入天数
);
dialog.setCancelable(true);

dialog.setCanceledOnTouchOutside(true);

          //设置最大时间

dialog.getDatePicker().setMaxDate(new Date().getTime());

    //设定时间样式

DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd",
Locale.CHINA);
Date myDate1 = null;
try {
myDate1 = dateFormat1.parse("2000-01-01");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}

//设置最小时间

dialog.getDatePicker().setMinDate(myDate1.getTime());
return dialog;
}

//自定义时间类。。。。。。。。。。
private class MyDatePickerDialog extends DatePickerDialog {


public MyDatePickerDialog(Context context, OnDateSetListener callBack,
int year, int monthOfYear, int dayOfMonth) {
super(context, DatePickerDialog.THEME_HOLO_LIGHT,
callBack, year, monthOfYear, dayOfMonth);
// TODO Auto-generated constructor stub


}





//在需要的地方可以调用CreateDialog().show()方法来显示时间对话框

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值