i have a onCreateDialog setted and i need to put 2 Dialogs (Datepicker and Timepicker) but when i put both of them inside onCreateDialog it only opens the first one which is Datepicker.
Code:
@Override
protected Dialog onCreateDialog(int id) {
//date picker
switch (id) {
case DATE_DIALOG_ID:
// set date picker as current date
return new DatePickerDialog(this, datePickerListener, year, month,day);
}
//time picker
switch (id) {
case TIME_DIALOG_ID:
//set time picker as current time
return new TimePickerDialog(this, timePickerListener, hour, minute,false);
}
return null;
}
Yes, you can, but your
switchis invalid. Correct syntax ofswitchis:and optionally
defaultto catch all the other values you do not have explicitcasefor. And you got two switches which is of no use. You correct code would be:also your IDs have to be unique, but once you fix the
switch, compiler will show error if you got it set to the same value (because you cannot have more than onecasefor given value).EDIT: I reworked this a bit again, because I personally dislike more than one exit point from the method – you got many
return.