开发者

DatePicker not responding to user input from Keyboard in Android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜