Description
While it is possible to change the style of a ListViewItem by changing the properties one by one (e.g. backgroundColor), it is not possible to use
addClass
,
removeClass
or
resetClass
to change them by using the classes.
Test code
index.xml
<Alloy autoStyle="true">
<Window>
<ListView id="list" defaultItemTemplate="fullItem" >
<Templates>
<ItemTemplate id="fullItem" name="fullItem" height="88">
<Label bindId="myview" class="firststyle"></Label>
</ItemTemplate>
</Templates>
<ListSection id="section" ></ListSection>
</ListView>
</Window>
</Alloy>
app.tss
".firststyle" : {
backgroundColor:"green"
},
".secondstyle" : {
backgroundColor:"yellow"
}
index.js
$.index.open();
var data = [{
myview : {
text: "One"
}
}, {
myview : {
text : "Two"
}
}];
$.section.setItems(data);
$.list.addEventListener('itemclick', function(e) {
var item = e.section.getItemAt(e.itemIndex);
// item.myview.backgroundColor = "red";
$.resetClass(item.myview, "secondclass");
e.section.updateItemAt(e.itemIndex, item);
});
Note
In the code above, note how changing the color works instead.
As I suspected, Ti.UI.ListItem does not support the
applyProperties()
function, which is critical to the dynamic style application process. I am marking this as "won't fix" as this won't be fixed in Alloy. I do suggest however that this issue be moved to TIMOB and better named to more precisely identify what the problem is here, as a fix in TIMOB for supportingapplyProperties
on ListItems would make this code work automatically in Alloy. Also, you didn't mention the actual error that occurs which identifies the missingapplyProperties
function as the culprit, so please add that before moving it to TIMOB.