Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 956
  • Last Modified:

Android Java DatePickerDialog. How do I set the initial date value?

This is hopefully a simple one.  I've been looking for ages but just can't find a solution.

I'm using showDialog to pop up the DatePickerDialog.  All aspects of this are fine.

I can't find out how to set the initial value the DatePickerDialog shows.  

I know you can set the value once in the onCreateDialog but I need to set it every time I show the dialog not just when its created.

I'm guessing there is some kind of object I can access I just can't find it anywhere.

Many Thanks
0
SamSherwin
Asked:
SamSherwin
2 Solutions
 
alexey_gusevCommented:
first of all, you have updateDate().
then, onPrepareDialog() is called every time you use showDialog()
0
 
SanthanaTechnical LeadCommented:
Hi  SamSherwin,

Refer this from android docs
http://developer.android.com/guide/topics/ui/dialogs.html

Before the dialog is displayed, Android also calls the optional callback method onPrepareDialog(int, Dialog). Define this method if you want to change any properties of the dialog each time it is opened. This method is called every time a dialog is opened, whereas onCreateDialog(int) is only called the very first time a dialog is opened. If you don't define onPrepareDialog(), then the dialog will remain the same as it was the previous time it was opened. This method is also passed the dialog's ID, along with the Dialog object you created in onCreateDialog().
0
 
SamSherwinAuthor Commented:
Thanks for the quick and good solution(s).  Sometimes when under pressure you just can see the wood for the trees.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now