Friday, January 21, 2011

TimePicker & DatePicker with keyboard edit problem

Problem: When using the TimePicker & DatePicker objects in an AlertDialog (and probably anywhere else), the time & date seem to not to update when the user is editing the value using a keyboard (or soft keyboard).

Solution: Before calling the functions to get the date & time from the objects call TimePicker or DatePicker clearFocus() method.

I found few threads talking about this problem without a solution. I found the solution when I looked at the TimePickerDialog source code which did not suffer from this problem.