小编aja*_*125的帖子

选择日期后,日期选择器应在 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();
} 
Run Code Online (Sandbox Code Playgroud)

java android date datepicker android-studio

5
推荐指数
1
解决办法
3327
查看次数

标签 统计

android ×1

android-studio ×1

date ×1

datepicker ×1

java ×1