3

I am using date and time picker in my application and referred the tutorial from here but the problem is that when i run it on kitkat 4.2.2 it show output as follows:enter image description here but when i run it on lollipop 5.1.1 it shows output enter image description here

showing two different UI on same code i dont know how to fix this problem.I have also applied some validations on it but its working with first case but not with second case.Please help.

Dhiraj
  • 870
  • 2
  • 12
  • 25

3 Answers3

4

if you want it identical to the first one you can add

android:datePickerMode="spinner" 
android:calendarViewShown="false"
Maxi
  • 979
  • 10
  • 16
3

This differs as per OS version in devices. It is a system date and time picker.

So it will be as per OS version and may - may not differ in each of the OS version.

Whatever you are seeing is correct and is OS level change.

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
  • but how to deal with validations with second screen because in my case validations not working for second approch – Dhiraj Feb 03 '16 at 10:55
  • all validations i applied like date should not be less than todays date and time picker user can not select time less than current time for todays date – Dhiraj Feb 03 '16 at 11:15
  • according to me it should work in both cases, in my app its working for all devices with different OS versions @Dhiraj OR show code – Amit Vaghela Feb 03 '16 at 11:17
  • or else user can select time between 6AM-10PM For other dates for validation purpose on time picker i have used http://stackoverflow.com/questions/13516389/android-timepickerdialog-set-max-time this for reference – Dhiraj Feb 03 '16 at 11:17
  • from this link, it should be working if you haved used it @Dhiraj – Amit Vaghela Feb 03 '16 at 11:23
  • its working for datepicker validation but not for time picker validation – Dhiraj Feb 03 '16 at 11:37
  • i am trying to work it but if it fails i will tell you – Dhiraj Feb 03 '16 at 11:37
  • @ Amit Vaghela ok just trying – Dhiraj Feb 03 '16 at 11:56
0

I think you can force it to look a certain way by changing compilessdkversion and the targetsdkversion accordingly in your gradle file.

edit: on second thought, I'm not 100% sure it'll work...might cause problems on some versions. The 100% positive way to get the classic spinner is like Maxi said to set the attribute datepickermode atribute to spinner. To answer whats been asked of Maxi regarding timePicker. You have to set the timePickerMode attribute to "spinner" in a similar fashion to avoid the round clock interface and get the classic spinner.

<TimePicker
    ...
     android:timePickerMode="spinner" />
Ilan Kutsman
  • 469
  • 3
  • 9