How do you get a DatePicker from a DatePickerDialog?

后端 未结 2 934
眼角桃花
眼角桃花 2021-01-02 07:38

I have a activity that is popping up a android.app.DatePickerDialog.

DatePickerDialog dialog =  new DatePickerDialog(this, startDateSetListener, start_cal.g         


        
相关标签:
2条回答
  • 2021-01-02 08:26

    Despite that getter method only being available in Honeycomb and above (as dmon correctly pointed out), you can still fairly easily get access to the DatePicker object encapsulated by the DatePickerDialog using reflection. It'll look something like this:

    DatePickerDialog dialog = ... // create dialog
    Field mDatePickerField = dialog.getClass().getDeclaredField("mDatePicker");
    mDatePickerField.setAccessible(true);
    DatePicker mDatePickerInstance = (DatePicker) mDatePickerField.get(dialog);
    

    From this point on, you have a reference to the internal DatePicker object and you should be able to change it to your own liking. Please do beware of any obvious typos, as I entered this directly into the browser.

    0 讨论(0)
  • 2021-01-02 08:26

    You misread, it's only available since API 11:

    "public DatePicker getDatePicker () Since: API Level 11". Look closely.

    0 讨论(0)
提交回复
热议问题