[TIMOB-16455] Android: Event object on ListItem child's change doesn't match iOS
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2020-02-19T13:48:53.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | parity |
Reporter | Tim Poulsen |
Assignee | Rene Pot |
Created | 2014-02-12T14:35:34.000+0000 |
Updated | 2020-02-19T13:48:53.000+0000 |
Description
Source: http://developer.appcelerator.com/question/162482/alloy-listview-with-switch-in-template
The event object, in particular e.source does not include the same properties as on iOS making it impossible to create a cross-platform solution to the developer's question.
In addition to the code I provided in that Q&A thread, I tried other solutions including this:
<Alloy>
<Window title="List item templates">
<ListView id="myList" defaultItemTemplate="myTemplate" top="20">
<Templates>
<ItemTemplate name="myTemplate" onChange="doSwitchMe">
<Switch bindId="checked" value="false" />
<Label bindId="title" left="40dp"/>
</ItemTemplate>
</Templates>
<ListSection id="mySection" headerTitle="A Section">
</ListSection>
</ListView>
</Window>
</Alloy>
var items=[];
for(var i=0; i<4; i++){
items.push({
title: {text: 'Title one'},
checked: {value: false, myID: 'switch'+i}
});
};
$.mySection.setItems(items);
function doSwitchMe(e) {
// result of next line is 'Switch undefined was clicked and is now on'
alert('Switch ' + e.source.myID + ' was clicked and is now ' + ((e.source.value===true)? 'on' : 'off'));
}
$.index.open();
In all cases, e.source doesn't include the custom myID property.
Attachments
File | Date | Size |
---|---|---|
Screen Shot 2014-02-12 at 9.07.13 AM.png | 2014-02-12T14:35:34.000+0000 | 97465 |
Screen Shot 2014-02-12 at 9.07.44 AM.png | 2014-02-12T14:35:34.000+0000 | 94639 |
Yes, this is an architecture parity between Android and iOS. We solved this by introducing 'itemId' property that you can use instead:
Defining a custom property on each list item is an acceptable workaround. But since the e.source.value property is valid on both platforms, it really seems as though the other properties of that child item should be accessible on the e.source object. I've updated the Q&A thread with the workaround. Thanks Hieu.