0

I am using the android dateslider custom dialog class in order to let the user edit the date for several different rows of a table.

The dateslider lets you limit the user to only select dates between a minimum date and maximum date that you can specify.

Each table row requires the dateslider to limit the user to a different minimum date and maximum date, however because you specify the min and max dates inside the onCreateDialog method, I need to be able to dynamically modify these dates when the user clicks the row.

I have tried calling the onCreateDialog method again when the user clicks the dialog, and it is ran, however the new limits are not taken into account, suggesting that the originally created dialog is still used instead.

How would I go about achieving my goal?

Thanks, Max.

nwalke
  • 3,170
  • 6
  • 35
  • 60
Max Mumford
  • 2,482
  • 5
  • 28
  • 40

1 Answers1

1

If you need to change dialogs before you use them, you need to use onPrepareDialog.

Update:

The dialog that is passed in to onPrepareDialog is the dialog that was created in onCreateDialog. Modify it however you like (don't create a new one). You might have to add some setters to your custom dialog class:

protected void onPrepareDialog(int id, Dialog dialog) {
    switch(id) {
    case YOUR_DIALOG_ID:
        YearMonthDayHourMinute myDialog = (YearMonthDayHourMinute) dialog;
        myDialog.setInitialTime(initialTime);
        myDialog.setMinTime(minTime);
        myDialog.setMaxTime(maxTime);
        break;
    }
}
kabuko
  • 36,028
  • 10
  • 80
  • 93
  • Thanks, just found that method. Here is my code: protected void onPrepareDialog (int id, Dialog dialog){ dialog = new YearMonthDayHourMinute(this, mDateSetListener, initialTime, minTime, maxTime); however this just edits the local copy of the variable. How would I access the dialog itself? } – Max Mumford Nov 18 '11 at 19:08
  • Great, thanks for the update! New to oop as you can see so still getting the mindset :P Cheers! – Max Mumford Nov 18 '11 at 20:01
  • Even easier solution was to call removeDialog(DIALOG_ID); and then showDialog(DIALOG_ID); - Editting the source of the dialog control was a bit too complex for me at the moment but your answer is still very relevent. Thanks – Max Mumford Nov 19 '11 at 11:37