Android日期与时间选择控件使用记录

 

日期选择

    private void showDatePickDialog(Activity activity, final TextView tv, final Calendar calendar) {
        new DatePickerDialog(
                activity,
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                        calendar.set(year, month, dayOfMonth);
                        tv.setText(getFormattedDateString(calendar));
                    }
                },
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH))
                .show();
    }

 

时间选择

    private void showTimePickDialog(Activity activity) {
        new TimePickerDialog(activity, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                settingValues.alarmHour = hourOfDay;
                settingValues.alarmMinute = minute;
                settingValues.saveValues();
                mRemindAlarmPreference.setSubtitleText(generateAlarmTimeString(hourOfDay, minute));
                if (settingValues.alarmEnabled) {
                    setAlarm(true, settingValues.alarmHour, settingValues.alarmMinute);
                }
            }
        }, settingValues.alarmHour, settingValues.alarmMinute, true).show();
    }

 

posted @ 2020-02-17 18:14  -ssdq-  阅读(548)  评论(0编辑  收藏  举报