Google+ Badge

Tuesday, October 25, 2011

Fun with Android DatePicker and 1970

I was doing a new round of testing on our Android tablet. The application is used for medical information entry and one of the fields is date of birth. It has been working like a champ on the phones using 2.01, 2.2, 2.3 but on the tablet running 4.1 you could not enter anything before 1970. You could type in 1963 and it would set it back to 1970 and the [-] button would disappear.

I totally get why it stops at 1970 as that is the epoch year used for all sorts of things in computers. Obviously the Android team changed a default in later versions of the SDK. My phone, running 2.2, allows you to go back to 1900.

After some research I found a solution that works for all devices I have tested against. In my XML file I added android:startYear="1900" to my definition. If you look in the latest documentation they discuss android:minDate but that is only available in later version of the SDK.

Before I stumbled upon startYear I tried to use reflection to call the setMinDate(long) on the datepicker but I did not have any luck doing that. I am really happy that was not the solution. I would much rather use something in the XML that solves it on all platforms.

Of course after I did this SVN got confused about a directory already being locked and would not allow me to check in the change. I found Team -> Cleanup in Eclipse solved that issue.

Now that I have my new "set favorites" processing in place on the Android I need to convert all that work over to the iPhone / iPad. Research time as some of it just does not have a direct translation to iOS and while the menu system is possible on the iPad it is officially not supported on the iPhone so I am going to have to come up with a work around. The first menu system I found has caused apps to be rejected by Apple due to private method usage making it a non-option. Dual iOS / Android development has a lot of headaches.