1

Hi i put the code of the examples in android developers in the same classe but i have a problem in this

@Override protected Dialog onCreateDialog(int id) {

            switch (id) {
            case DATE_DIALOG_ID:
                return new DatePickerDialog(this,
                            mDateSetListener,
                            mYear, mMonth, mDay);  

            case TIME_DIALOG_ID:
                return new TimePickerDialog(this,
                        mTimeSetListener, mHour, mMinute, false);
                }
            return null;
        }

why i can't do this??

it only works with one case..

jpmd
  • 247
  • 1
  • 7
  • 19

3 Answers3

1

when declaring static fields for DATE_DIALOG_ID and TIME_DIALOG_ID, set different values. eg. DATE_DIALOG_ID = 0; TIME_DIALOG_ID = 1; This should solve your problem.

Bharath
  • 11
  • 1
0

When using switch, its case can never be same, they must be distinct.

Here DATE_DIALOG_ID and TIME_DIALOG_ID both are constants and it looks like they must be having same values. Check their values, if they are same then change it. I am sure changing their value will not change anything in your DatePicker or TimePicker.

Community
  • 1
  • 1
Amit Anand
  • 1,225
  • 1
  • 16
  • 40
0

Try in this way: DateTime picker in android application

Community
  • 1
  • 1
Jaydeep Khamar
  • 5,975
  • 3
  • 32
  • 30
  • i have the same but gives a error in the code that i posted. The error is duplicated case.. – jpmd May 06 '11 at 13:24