1. 程式人生 > >android客戶端學習-日期彈出框並設定可選最大最小日期

android客戶端學習-日期彈出框並設定可選最大最小日期

Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int monthOfYear = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(activity.this, new DatePickerDialog.OnDateSetListener() {
    @Override
public void onDateSet(DatePicker datePicker, int yyyy, int mm, int dd) { birthday = yyyy + "-" + (mm + 1) + "-" + dd; } }, year, monthOfYear, dayOfMonth); DatePicker datePicker = datePickerDialog.getDatePicker(); Date taday = Calendar.getInstance().getTime();//當天 try { datePicker.setMinDate(taday.getTime());// 最小日期
datePicker.setMaxDate(taday.getTime());// 最大日期 } catch (Exception e) { } datePickerDialog.show();