3
我正在使用Android的默認日期選擇器,現在我想關閉對話框 選擇日期後,日期選擇器應該關閉在Android沒有點擊好的按鈕選擇日期後,日期選擇器應該關閉在Android沒有點擊好的按鈕
private void updateDOB() {
String myFormat = "yyyy/MM/dd"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
btnDOB.setText(sdf.format(calendar.getTime()));
tvDOB.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
}
private void selectDOB() {
DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
updateDOB();
}
};
new DatePickerDialog(ActivityAddChild.this, listener,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)).show();
}