Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I set up a minimum and maximum date with DatePicker?

 
Andrew Tyrer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuck on how to set up a minimum and maximum date with the DatePicker, so for instance the user can't set the date pass the current date. Similarly the user won't be able select a date before 1960, so far I've been able to set up the DatePicker my code is below:

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew and Robert,

Welcome to the Ranch, the two of you!

The pertinent information comes from these two pages of the API:
DatePickerDialog: http://developer.android.com/reference/android/app/DatePickerDialog.html
DatePicker: http://developer.android.com/reference/android/widget/DatePicker.html

When you are creating the DatePickerDialog, but before you display it, you need to get the DatePicker which is displayed in the dialog. If you look in the API link for DatePickerDialog you should find the method you need to do that rather simply. Then once you have the DatePicker finding the correct methods to call on the DatePicker is also trivial if you look at that class' API. I think the only things left to do are to 1) create the dates you want to set as min and max, and 2) convert those dates to the proper format required by the API.

[ UD: fixed URL of DatePicker javadoc ]
 
Andrew Tyrer
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, I sound silly right now, but I still don't understand. Are you able to explain via an example, thanks
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you confused? What do you have so far, now that you have read the API?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic