[TIMOB-19192] Android: Date & Time Picker change event not fired nor is picker.value updated
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2015-10-01T23:24:28.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.2.0 |
Components | Android |
Labels | datepicker |
Reporter | Justin Toth |
Assignee | Ashraf Abu |
Created | 2015-04-28T15:21:32.000+0000 |
Updated | 2016-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
File | Date | Size |
---|---|---|
Ti SDK3.5.1 GA.png | 2015-04-29T06:47:55.000+0000 | 70453 |
Ti SDK 4.0.0 RC.png | 2015-04-29T06:47:52.000+0000 | 57318 |
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!
Hello [~michielve]. May I know which version of Android you are using and the device?
Android 5.0+ are facing this bug
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
PR: https://github.com/appcelerator/titanium_mobile/pull/6985
PR merged.
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
[~lchoudhary] Could you describe what you did exactly and the results of it? Thanks!
[~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.
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.
Could you let me know which test code you are using as well as the device information?
[~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
Thank you for the info. Will look into it.
[~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.
[~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
PR for fix: https://github.com/appcelerator/titanium_mobile/pull/7094
PR merged
[~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
Test code I used was:
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.
Reverting the PR: https://github.com/appcelerator/titanium_mobile/pull/7105
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.
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?
Closing as duplicate.