Question

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.

Was it helpful?

Solution

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top