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(); }
如果转载,请注明出处。https://www.cnblogs.com/ssdq/