Custom DatePicker as Preference does not keep value when user edits value in field

前端 未结 3 1066
攒了一身酷
攒了一身酷 2021-02-04 19:09

I created a DatePickerPreference, i.e. I extended DialogPreference and created a DatePicker object inside and had it working almost perfectly. It changes values when you click t

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 19:26

    I had the same issue. The solution is very simple. The date picker updates the edited values only when it losts focus, so before getting the values you have to call:

    datePicker.clearFocus();
    

    After this call you can call:

    selectedDay = datePicker.getDayOfMonth();
    selectedMonth = datePicker.getMonth();
    

    and have the values updated.

提交回复
热议问题