Using Android Date Picker

Using android Date Picker

This is a sample activity which shows how to use Date picker control.

Underlying Algorithm:

Basic description of algorithm in step by step form:
1.) Create a Project DatePickerExample.
2.) Create a date_picker.xml in res/layout.
3.) Put the following code in date_picker.xml :

 

 

 

4.) To create a date picker control we need the following imports :

 

 

 

5.) Run the application.

Steps to Create:

1.) Open Eclipse. Use the New Project Wizard and select Android Project Give the respective project name i.e. DatePickerExample. Enter following information:
Project name: DatePickerExample
Build Target: Google APIs
Application name: DatePickerExample
Package name: com.sample.DatePickerExample
Create Activity: DatePickerExample

On Clicking Finish DatePickerExample code structure is generated with the necessary Android Packages being imported along with DatePickerExample.java. DatePickerExample class will look like following:

 

 

 

Output –The final output:

Comments 11

  1. Thanks dude,that worked well…….

    just wanted to know the other thing how will i embed this date function with other application of android

    • You can call below lines anywhere in other android application and use mYear/mMonth/mDay to play with date.

      [code lang=”java”]
      final Calendar c = Calendar.getInstance();
      mYear = c.get(Calendar.YEAR);
      mMonth = c.get(Calendar.MONTH);
      mDay = c.get(Calendar.DAY_OF_MONTH);
      [/code]

      I hope I am getting you correctly.

  2. I get the same as you, but it is difficult to change the year. I have been searching how toget a ‘nicer’ dialog, and it may be to set the them parameter. But I am not sure what tis points to.. Is it an XML file that defines the dialog.

    I know the problem with the dialog is that it is too big for the screen. Rotating sometimes shows a ‘scrollable’ year, or part of the text for the year. (a lot of 20 to gues which one is 2004).

    Any clues on where to look for a them for a dateDialog?

  3. I get the same as you, but it is difficult to change the year. I have been searching how toget a ‘nicer’ dialog, and it may be to set the them parameter. But I am not sure what tis points to.. Is it an XML file that defines the dialog.

    I know the problem with the dialog is that it is too big for the screen. Rotating sometimes shows a ‘scrollable’ year, or part of the text for the year. (a lot of 20 to gues which one is 2004).

    Any clues on where to look for a them for a dateDialog?

  4. Hi, How I Can add Two Button Simultaneously In Single Layout Activity.
    And Both Calander Sholud Display Different Date in Both Text View.
    Give Me Code If Requre Any New Plz.

    Thanx In Advance.

Leave a Reply

Your email address will not be published. Required fields are marked *