0

I am using a date picker to set an alarm but this is also allowing user to set the dates even before current date here is my code to set date picker

public void onClick(View v) {

            new DatePickerDialog(ReminderDetailActivity.this, date,
                    myCalendar.get(Calendar.YEAR), myCalendar
                            .get(Calendar.MONTH), myCalendar
                            .get(Calendar.DAY_OF_MONTH)).show();

        }

can anyone tell me hoe to restrict user from going to past dates

thank you in advance

Dude
  • 173
  • 2
  • 4
  • 14
  • Here's [a link](http://stackoverflow.com/questions/4943486/android-datepicker-date-limiting) http://stackoverflow.com/questions/4943486/android-datepicker-date-limiting – Alex Park Jun 27 '14 at 10:29

1 Answers1

1

You could use something like this.

Calendar c = Calendar.getInstance();
int todaysDate = c.get(Calendar.DATE);

 public void onClick(View v) {

            new DatePickerDialog(ReminderDetailActivity.this, date,
                    myCalendar.get(Calendar.YEAR), myCalendar
                            .get(Calendar.MONTH), myCalendar
                            .get(Calendar.DAY_OF_MONTH)).show();

                         if(todaysDate < date){
                    Toast.makeText(Activity.this, "choose a future date",Toast.LENGTH_SHORT).show();
    }else{
                    //execute normal function
    }


   }
Mohammod Hossain
  • 4,134
  • 2
  • 26
  • 37
user3331142
  • 1,222
  • 1
  • 11
  • 22