开发者

DatePicker not responding to user input from Keyboard in Android

开发者 https://www.devze.com 2023-01-31 18:20 出处:网络
I have a DatePicker in my activity. It works fine except when the user enters the date via the keypad and does not use the + or - buttons to change date.

I have a DatePicker in my activity. It works fine except when the user enters the date via the keypad and does not use the + or - buttons to change date. The date returned when the user edits via keyboard is always what i开发者_开发百科s the DatePicker is initialized with. When debug I notice the onDateChanged() callback is never called except when the date is change using the buttons.


Yep, I meet this issue too. The datepicker will save the change only if you remove the focus from the active edittext. So you have to run "mDatePicker.clearFocus();" before you get the date from it.


Look at this solution...

DatePicker dp = (DatePicker) findViewById(R.id.datePicker1);
dp.clearChildFocus(getCurrentFocus());
int day = dp.getDayOfMonth();
int month = dp.getMonth();
int year = dp.getYear();

... using "clearFocus" the DatePicker won't completely save user changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消