Articles → Android → Datepicker Dialog In Android

Datepicker Dialog In Android






Example






Picture showing the textview control inside the constraint layout
Click to Enlarge



@Nullable
@Override
protected Dialog onCreateDialog(int id) {
    return new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            TextView textView = (TextView) findViewById(R.id.tvGetDate);
            textView.setText(String.valueOf(year) +
                "-" + String.valueOf(month) + "-" + String.valueOf(dayOfMonth));
        }
    }, 2019, 10, 31);
}




showDialog(0);



Output




Picture showing the datepicker dialog on screen load in android
Click to Enlarge



Picture showing the selected date on the textview in android application
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, November 25, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250