Android TimePickerView使用方法

  • 源代码未附上,需要的请私密我...
  • 一般使用方法
TimePickerView pvTime = new TimePickerView(context, TimePickerView.Type.YEAR_MONTH_DAY);
                            pvTime.setTime(Time.nowDate());
                            pvTime.setCancelable(true);
                            pvTime.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {
                                public void onTimeSelect(Date date) {
                                    MyToast.showInfo(Time.date2StrYM(date), context);
                                    MyToast.showInfo(Time.date2StrYMD(date), context);
                                }
                            });
                            pvTime.show();
  • 复杂

  • private TimePickerView pvTime;

     

    pvTime = new TimePickerView(context, TimePickerView.Type.YEAR_MONTH_DAY);
            pvTime.setCancelable(true);
            pvTime.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {
                public void onTimeSelect(Date date) {
                    //选择日期早于now
                    if (date.getTime() <= new Date().getTime())
                        txtDate.setText(Time.date2StrYMD(date));
                    else MyToast.showInfo("血压记录: 日期不得迟于今天", context);
                }
            });
    //每次点击时间选择: 内置时间都会从Textview中读取
                    pvTime.setTime(Time.str2Date(txtDate.getText().toString()));
                    pvTime.show();

转载于:https://www.cnblogs.com/guixianfeng/p/5105556.html

你可能感兴趣的:(Android TimePickerView使用方法)