美文网首页
DatePickerDialog、TimePickerDialo

DatePickerDialog、TimePickerDialo

作者: 43d60efa37c7 | 来源:发表于2016-12-12 11:19 被阅读213次

用法:

// 获取日历对象

Calendar calendar = Calendar.getInstance();

// 获取当前对应的年、月、日的信息

final int year = calendar.get(Calendar.YEAR);

final int month = calendar.get(Calendar.MONTH);

final int day = calendar.get(Calendar.DAY_OF_MONTH);

new DatePickerDialog(mActivity,android.R.style.Theme_Holo_Light_Dialog,

              new  DatePickerDialog.OnDateSetListener() {

                      @Override

                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

                                      //点击完成调用,自己做处理

                        }

                },year, month, day){

                          @Override

                          protected void onStop() {

                                      //解决执行两次onDateSet的bug,注释掉就可以了

                                      // super.onStop();

              }

}.show();

注意:

一、设置主题

二、重写onStop方法,不执行父类里的onStop,不然onDateSet()方法会执行两次

TimePickerDialog的用法、注意与DatePickerDialog相同

相关文章

网友评论

      本文标题:DatePickerDialog、TimePickerDialo

      本文链接:https://www.haomeiwen.com/subject/lcjmmttx.html