Problem with datepicker and timepicker

◇◆丶佛笑我妖孽 提交于 2019-12-24 10:00:08

问题


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..


回答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.




回答2:


Try in this way: DateTime picker in android application




回答3:


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.



来源:https://stackoverflow.com/questions/5911721/problem-with-datepicker-and-timepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!