Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19192] Android: Date & Time Picker change event not fired nor is picker.value updated

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2015-10-01T23:24:28.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.2.0
ComponentsAndroid
Labelsdatepicker
ReporterJustin Toth
AssigneeAshraf Abu
Created2015-04-28T15:21:32.000+0000
Updated2016-01-19T17:03:35.000+0000

Description

On Android 5, the Titanium date picker is broken. 1. It no longer fires the changed event so you can't obtain the selected value as it updates. This happens whether on Ti SDK 4.X or 3.5.1.GA. 2. It no longer updates the picker.value so you can't obtain the selected value on demand. This works on Ti SDK 3.5.1.GA, so seems to be an issue only on Ti SDK 4.X.
Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow({
    exitOnClose: true,
    layout: 'vertical'
});

var picker = Ti.UI.createPicker({
    type:Ti.UI.PICKER_TYPE_DATE,
    minDate:new Date(2009,0,1),
    maxDate:new Date(2014,11,31),
    value:new Date(2014,3,12),
    top:50
});

win.add(picker);
win.open();

picker.addEventListener('change',function(e){
    alert("User selected date: " + e.value.toLocaleString());
});

setTimeout(function() {
    alert('picker.value: ' + picker.value);
}, 10000);
Note that this alternative approach works:
Ti.UI.backgroundColor = 'white';

var picker = Ti.UI.createPicker({
    type:Ti.UI.PICKER_TYPE_DATE,
    minDate:new Date(2009,0,1),
    maxDate:new Date(2014,11,31),
    value:new Date(2014,3,12)
});

picker.showDatePickerDialog({
    value: new Date(2010,8,1),
    callback: function(e) {
        if (e.cancel) {
            alert('User canceled dialog');
        } else {
            alert('User selected date: ' + e.value);
        }
    }
});

Attachments

FileDateSize
Ti SDK3.5.1 GA.png2015-04-29T06:47:55.000+000070453
Ti SDK 4.0.0 RC.png2015-04-29T06:47:52.000+000057318

Comments

  1. Michiel van Eerd 2015-07-08

    This also affects the time picker (UI.PICKER_TYPE_TIME) when building with SDK 4.0.0 on Android. This has even more impact than the DATE picker, because the showDatePickerDialog() method does not show TIME pickers, so we have no way to get the value of TIME pickers in SDK 4.0.0!
  2. Ashraf Abu 2015-07-24

    Hello [~michielve]. May I know which version of Android you are using and the device?
  3. Wilson Liaw 2015-07-24

    Android 5.0+ are facing this bug
  4. Ashraf Abu 2015-07-27

    An update on this issue. This seems to be a native bug in Android 5.0 which Google fixed in Android 5.1. Android Issue Tracker:- https://code.google.com/p/android/issues/detail?id=147657&can=1&q=onDateChanged&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
  5. Ashraf Abu 2015-07-27

    PR: https://github.com/appcelerator/titanium_mobile/pull/6985
  6. Ashraf Abu 2015-07-30

    PR merged.
  7. Lokesh Choudhary 2015-08-18

    The issue persists on android 5.0.X. The change event only fires once for me. Reopening. Environment: Appc Studio : 4.2.0.201508062204 Ti SDK : 5.0.0.v20150818082827 Ti CLI : 4.1.4 Alloy : 1.6.2 MAC Yosemite : 10.10.4 Appc NPM : 4.1.0 Appc CLI : 4.2.0-57 Node: v0.10.37 One plus one - Android 5.0.1 Node : v0.10.37
  8. Ashraf Abu 2015-08-24

    [~lchoudhary] Could you describe what you did exactly and the results of it? Thanks!
  9. Lokesh Choudhary 2015-08-24

    [~msamah]- I ran the code above on an android 5.0.X device & the alert on a change event was fired only once/first time after launching the app & changing the date.
  10. Ashraf Abu 2015-08-25

    I'm currently using HTC Desire Eye running Android version 5.0.2 and it is working for me. I can change and the value is updated multiple times. This code is working fine for me on the Master branch.
        picker2.addEventListener('change',function(e){
         
         
            alert("User selected date: " + e.value.toLocaleString());
         
            
        });
        
  11. Ashraf Abu 2015-08-25

    Could you let me know which test code you are using as well as the device information?
  12. Lokesh Choudhary 2015-08-25

    [~msamah], I am using the code in the description & in your PR on git hub. Device used is One Plus One - Android 5.0.1
  13. Ashraf Abu 2015-08-25

    Thank you for the info. Will look into it.
  14. Ashraf Abu 2015-08-25

    [~lchoudhary], could you try this on an Android 5.0.0 and Android 5.0.2? I would like to know if it's affected as well.
  15. Lokesh Choudhary 2015-08-25

    [~msamah], On checking today with build 5.0.0.v20150825082243 I see a different behaviour, on android 5.0 emulator, One plus one - android 5.0.2 & android 5.0.1 emulator, I get alert twice for a change event. Environment: Appc Studio : 4.2.0.201508141038 Ti SDK : 5.0.0.v20150825082243 Ti CLI : 4.1.5 Alloy : 1.7.5 MAC Yosemite : 10.10.4 Appc NPM : 4.2.0-1 Appc CLI : 5.0.0-14 Node: v0.10.37 Nexus 5 - Android 5.1.1 Node : v0.10.37
  16. Ashraf Abu 2015-08-31

    PR for fix: https://github.com/appcelerator/titanium_mobile/pull/7094
  17. Ashraf Abu 2015-08-31

    PR merged
  18. Lokesh Choudhary 2015-09-01

    [~msamah], I did not get what does you fix does. I don't see the alert for the change event again. checked with the code in the description on android 5.0.0. Reopening. Environment: Appc Studio : 5.0.0.201508251028 Ti SDK : 5.0.0.v20150831142846 Ti CLI : 4.1.5 Alloy : 1.7.6 MAC Yosemite : 10.10.4 Appc NPM : 4.1.0-2 Appc CLI : 5.0.0-33 Node: v0.10.37 Nexus 5 - Android 5.0.0 Node : v0.10.37
  19. Ashraf Abu 2015-09-01

    Test code I used was:
        var vidWin = Titanium.UI.createWindow({
            title : 'Video View Demo',
            backgroundColor : '#000'
        });
         
        var picker = Ti.UI.createPicker({
            type:Ti.UI.PICKER_TYPE_DATE,
            minDate:new Date(2009,0,1),
            maxDate:new Date(2014,11,31),
            value:new Date(2014,3,12)
        });
        var button = Titanium.UI.createButton({
           title: 'Picker',
           top: 10,
           width: 100,
           height: 50
        });
        button.addEventListener('click',function(e)
        {
        	picker.showDatePickerDialog({
        	    value: new Date(2010,8,1),
        	    callback: function(e) {
        	        if (e.cancel) {
        	            alert('User canceled dialog');
        	        } else {
        	            alert('User selected date: ' + e.value);
        	        }
        	    }
        	});
        });
         
        ///
         
         
        var picker2 = Ti.UI.createPicker({
            type:Ti.UI.PICKER_TYPE_DATE,
            minDate:new Date(2009,0,1),
            maxDate:new Date(2014,11,31),
            value:new Date(2014,3,12),
            top:120
        });
        picker2.addEventListener('change',function(e){
         
         
            alert("User selected date: " + e.value.toLocaleString());
         
            
        });
         
        var button2 = Titanium.UI.createButton({
           title: 'Picker',
           top: 60,
           width: 100,
           height: 50
        });
        button2.addEventListener('click',function(e)
        {
        	 alert('picker2.value: ' + picker2.value);
        });
         
        vidWin.add(button);
        vidWin.add(picker2);
        vidWin.add(button2);
        vidWin.open();
        
    Is it possible for u to test it on a 5.0.0, 5.0.1 and 5.0.2? I'll look into this more.
  20. Ashraf Abu 2015-09-01

    Reverting the PR: https://github.com/appcelerator/titanium_mobile/pull/7105
  21. Ashraf Abu 2015-09-03

    Tried the code on Android 5.0.2 with latest Master and callback is called twice. Tried this natively on Android Studio with native code and callback is called twice. Seems to be a native issue.
  22. Ashraf Abu 2015-09-04

    Creating and running a simple native app on Android Studio with the Date Picker does indeed call the callback twice when changing the date. What would be a good way to resolve this issue?
  23. Ashraf Abu 2015-10-01

  24. Lokesh Choudhary 2016-01-19

    Closing as duplicate.

JSON Source