Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 954287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:11:30+00:00 2026-05-16T00:11:30+00:00

Can any one post sample code for a simple date picker in Android. If

  • 0

Can any one post sample code for a simple date picker in Android.

If date picker is not possible in Android, an option to choose a date is needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:11:30+00:00Added an answer on May 16, 2026 at 12:11 am

    Use the DatePicker

    http://developer.android.com/reference/android/widget/DatePicker.html

    It is availible since API Level 1

    Here a example how to use the DatePickerDialog.

    First add a TextView and a Button to your layout.xml

    <Button android:id="@+id/myDatePickerButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Choose Date"/>
    
    <TextView android:id="@+id/showMyDate"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>
    

    Next you have to initialize the Button and TextView in the onCreate Method of your layout.
    You need this class variables

    private int mYear;
    private int mMonth;
    private int mDay;
    
    private TextView mDateDisplay;
    private Button mPickDate;
    
    static final int DATE_DIALOG_ID = 0;
    

    Here the onCreate method

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        mDateDisplay = (TextView) findViewById(R.id.showMyDate);        
        mPickDate = (Button) findViewById(R.id.myDatePickerButton);
    
        mPickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });
    
        // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
    
        // display the current date
        updateDisplay();
    }
    

    UpdateDisplay method:

    private void updateDisplay() {
        this.mDateDisplay.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mMonth + 1).append("-")
                    .append(mDay).append("-")
                    .append(mYear).append(" "));
    }
    

    The callback listener for the DatePickDialog

    private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, 
                                  int monthOfYear, int dayOfMonth) {
                mYear = year;
                mMonth = monthOfYear;
                mDay = dayOfMonth;
                updateDisplay();
            }
        };
    

    The onCreateDialog method, called by showDialog()

    @Override
    protected Dialog onCreateDialog(int id) {
       switch (id) {
       case DATE_DIALOG_ID:
          return new DatePickerDialog(this,
                    mDateSetListener,
                    mYear, mMonth, mDay);
       }
       return null;
    }
    

    Hope it helps, used it and it works fine.

    Example from

    http://developer.android.com/guide/tutorials/views/hello-datepicker.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone post a sample code wherein theres a running timer(javascript settimeout) and doing
Can any one tell, how to get the result of LINQ query contains group
Can any one explain difference between position and anchor point in cocos-2D with some
Can any one tell me how can I make divs visible in ASP.NET. I
Can any one help in transforming my xml though XSLT. I am new to
can any one tell me how to implement a standalone java client for playing
Can any one tell me? what does following means in ruby program: obj =
Any one help me . I am using the following code for calling web
Let me start by saying that I am not an expert in any one
Can anyone post the steps for integrating mercurial to phped. I followed the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.