简体   繁体   中英

Android: Force recreation of dialog

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.

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM