[TIMOB-26104] Android: Removing and re-adding drop-down picker resets last selection
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-10-02T17:54:17.000+0000 |
Affected Version/s | Release 6.2.0 |
Fix Version/s | Release 7.5.0 |
Components | Android |
Labels | android |
Reporter | Alexander de Greiff |
Assignee | Yordan Banev |
Created | 2018-06-04T17:10:17.000+0000 |
Updated | 2018-10-02T17:54:34.000+0000 |
Description
Starting with Ti 7.x incl. 7.1.1GA on Android the pickerview, when inside a tableview, resets its selected value after events like orientationchange, scroll outside of window and back in or focus on another ui element.
(works perfectly on ios and used to work perfectly on Ti<=6.x)
example code:
{{
var currentwindow = Ti.UI.createWindow({
});
var tabledata = [];
var picker = Ti.UI.createPicker({
top:20
});
var data = [];
data[0]=Ti.UI.createPickerRow({title:'Bananas'});
data[1]=Ti.UI.createPickerRow({title:'Strawberries'});
data[2]=Ti.UI.createPickerRow({title:'Mangos'});
picker.add(data);
var myrow=Ti.UI.createTableViewRow({
'height' : '50sp'
});
myrow.add(picker);
tabledata.push(myrow);
var infotableview = Titanium.UI.createTableView({
data:tabledata,
});
currentwindow.add(infotableview);
//currentwindow.add(picker);
}}
what will happen with this issue now? do you need more info?
I couldn't locate the problem but these _could_ be related to the bug: When e.g. the orientation changes the picker is created again and it is losing its [old selection value (TiUINativePicker.java)](https://github.com/appcelerator/titanium_mobile/blob/cd91879899ff3629ae78b369e1aa67ca57f48999/android/modules/ui/src/java/ti/modules/titanium/ui/widget/picker/TiUINativePicker.java#L215). These PRs did some changes https://github.com/appcelerator/titanium_mobile/pull/9763/files https://github.com/appcelerator/titanium_mobile/pull/9917/files https://github.com/appcelerator/titanium_mobile/pull/9963/files so that would be a good place to start some debugging. If I have some more spare time I might have a look again, too
Okay. So, I've confirmed that this is not just an issue with a
TableView
. The root issue here is that if you remove the picker from a window and then re-add it, the picker will forget its last selected item and reset to the 1st item. The reason this can happen with aTabelView
too is because Android's native behavior is to remove views that are scrolled off (for performance reasons) and then re-add them when they're scrolled-in. (I'm curious if this would be an issue withTabGroups
as well.) Here's how to reproduce this issue without aTableView
... *Steps to reproduce:*Build and run the below code on Android.
Tap on the picker.
Select a picker item other than "Item 1".
Tap on the "Remove Picker" button. (This removes it from the window.)
Tap on the "Add Picker" button. (This re-adds it to the window.)
Notice that the picker's selection has been reset to "Item 1".
[~ybanev], this is an issue with the picker, not the table view. I think the solution may be to override the picker's
onAttachedToWindow()
method and restore the selection there. It's worth a shot.[~adegreiff], is there any reason you're using a
TableView
instead of aScrollView
? I ask because aScrollView
is significantly simpler and would not have this picker issue.[~jquick] , we have some enterprise client apps in production where the tableview is the central scaffold and the rows and containing ui objects/properties are coming from the server and interpreted/cached in the client (titanium classic). we are evaluating listviews but they are not as flexible as the layout can change with every row coming from the server.
I've tested for this issue in Titanium 6.0.2 and have confirmed that the picker "forgets" its last selection when detached/re-attached to the window as well. This looks like a Google issue/limitation with the picker that has always existed that we need to work-around. Perhaps Titanium's
TableView
has work-around it at one point, but regardless, this issue needs to be resolved in the picker's Java code. We'll look into it. Thanks for reporting this issue.PR: https://github.com/appcelerator/titanium_mobile/pull/10211
FR passed.
Closing since FR passed as well.