Lets see how to code datepicker in android. You should have seen this various applications for example in ticket reservation apps. Its very simple to program this Datepicker dialogbox functionality. You need to have an editText, ImageButton components in activitymain.xml.
When you click on Imagebutton it should open a dialog box with todays date and while clicking on "set" it will set the value in editText component. To get todays date we need to create instance for Calendar class and get year, month and day.
cal = Calendar.getInstance();
day = cal.get(Calendar.DAY_OF_MONTH);
month = cal.get(Calendar.MONTH);
year = cal.get(Calendar.YEAR);
Then we need to set the ImageButton to invoke calendar dialogbox.
This will return the DatePickerDialog with todays date.
return new DatePickerDialog(this, datePickerListener,year, month, day);
This is a constructor with some define parameters.
datePickerListener - This is a callback to indicate the date has been set.
Object for this listener is created as follows,
DatePickerDialog.OnDateSetListener datePickerListener =new DatePickerDialog.OnDateSetListener()
Once the date is set this will invoke , "onDateSet" method to perform user define functionality where we have assigned the date value to editText.
Source code of this application
Thats it, simple..!! We are done with datepicker in Android.
Have a look at Android Time picker example. Quite a similar one.