recently i used datepicker Dialog in my application but i got into a weird problem the datepicker dialogue was not updating for second time even though i called the showDialog and after searching on the net in vain i finally found out the solution in Android documents and partial method on one website and finally tailored it and got it worked.
onCreateDialog will only create the dialogue for first time but if we want to update it for second or consecutive time we have to write onPrepareDialog which is automatically called by showDialog below is the sample snippet for datepicker and this is similar for almost all the different dialogs
onCreateDialog will only create the dialogue for first time but if we want to update it for second or consecutive time we have to write onPrepareDialog which is automatically called by showDialog below is the sample snippet for datepicker and this is similar for almost all the different dialogs
showDialog(calldailogue);// calling date picker dialogue
Below is the code for calling datepicker first time
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case calldailogue:
return new DatePickerDialog(this, yourlistener, year, month,
day);
}
return null;
}
but in case you want to update the datepicker view and two show different value each time you have to use onPrepareDialog as showDialogue will not call onCreateDialog second time it calls onPrepareDialog below is the code to refresh datepicker for second time
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case calldailogue:
((DatePickerDialog) dialog).updateDate(year, month, day);
}
}
when i came across this issue for first time it really took 3hrs to figure it out and fix the issue as i did not find this information anywhere on the web
12 comments:
tnx dude i've been searching the net for the same thing...very helpfull!!
thanks for the solution, it was very usefull
thanks! I spent 1 hour searching it :-)
Thanks Manjunath... This was really a great help. Was facing the same issue with ProgressDialog
Finally.. thanks!! :)
Thank you mate!
Thanks it saved me. I spent one hour searching on my own then google and got there.
Thank you a lot!!!
you're a legend. Nice one
Finally I finded de solution, thanks guy!!!
thanks!
Thank you so much..I was searching for a solution to this for 2 hours..
Post a Comment