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

  • SEARCH
  • Home
  • 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 7858323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:23:14+00:00 2026-06-02T21:23:14+00:00

I am using a date picker dialog for selecting the date of birth of

  • 0

I am using a date picker dialog for selecting the date of birth of the users, so i am able to display the dialog. but the user should not be allowed to increase the year or date or month than present date. How can i do this?

Here is my code:

private int mYear;
     private int mMonth;
     private int mDay;
     static final int DATE_DIALOG_ID = 1;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.main);   

             Button pickDate = (Button) findViewById(R.id.but);
             pickDate.setOnClickListener(new View.OnClickListener() {
                     public void onClick(View v) {
                             showDialog(DATE_DIALOG_ID);
                     }
             });
             final Calendar c = Calendar.getInstance();
             mYear = c.get(Calendar.YEAR);
             mMonth = c.get(Calendar.MONTH);
             mDay = c.get(Calendar.DAY_OF_MONTH);             
     }
     @Override
     protected Dialog onCreateDialog(int id) {
             switch (id) {
             case DATE_DIALOG_ID:
                     return new DatePickerDialog(this,
                             mDateSetListener,
                             mYear, mMonth, mDay);
             }
             return null;
     }
     protected void onPrepareDialog(int id, Dialog dialog) {
             switch (id) {
             case DATE_DIALOG_ID:
                     ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
                     break;
             }
     }    

     private DatePickerDialog.OnDateSetListener mDateSetListener =
             new DatePickerDialog.OnDateSetListener() {
             public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

                        if (year > mYear)
                        view.updateDate(mYear, mMonth, mDay);

                        if (monthOfYear > mMonth && year == mYear)
                        view.updateDate(mYear, mMonth, mDay);

                        if (dayOfMonth > mDay && year == mYear && monthOfYear == mMonth)
                        view.updateDate(mYear, mMonth, mDay);
             }
     };

Thank you.

  • 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-06-02T21:23:15+00:00Added an answer on June 2, 2026 at 9:23 pm
    @Override
         protected Dialog onCreateDialog(int id) {
                 switch (id) {
                 case DATE_DIALOG_ID:
                         DatePickerDialog _date =  new DatePickerDialog(this,  mDateSetListener,
                                 mYear, mMonth, mDay){
                    @Override
                    public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth)
                    {   
                         if (year > mYear)
                            view.updateDate(mYear, mMonth, mDay);
    
                            if (monthOfYear > mMonth && year == mYear)
                            view.updateDate(mYear, mMonth, mDay);
    
                            if (dayOfMonth > mDay && year == mYear && monthOfYear == mMonth)
                            view.updateDate(mYear, mMonth, mDay);
    
                    }
                };
                return _date;
         }
         }
    

    you must use the above oncreate dialog for restricting future dates

    private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, 
                    int monthOfYear, int dayOfMonth) {
                          //do your stuff when user clicks on set button in dialog  
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am using Date Picker in my screen. But the problem is its not displaying
Hello I am using two buttons which on click show date picker dialog and
I am using the jQuery Date picker, but it is too heavy, the minified
I'm using the jQuery date picker widget and it works nicely but I'm confused
This should hopefully be a simple one. When using a date time picker in
I am currently using a date and time picker to retrieve a user-submitted date
Hi i am using an date picker on selecting a date the date is
I am using a standard date picker to allow the user to pick a
I'm using a usoft date time picker control in a dialog box. I started
I am using the date picker provided by jQuery UI to select a date

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.