Titanium JIRA Archive
Alloy (ALOY)

[ALOY-899] Cannot add/remove class from ListViewItem

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionWon't Fix
Resolution Date2013-12-13T15:16:36.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterDavide Cassenti
AssigneeTony Lukasavage
Created2013-12-13T14:53:41.000+0000
Updated2014-06-22T13:23:16.000+0000

Description

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.

Comments

  1. Tony Lukasavage 2013-12-13

    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 supporting applyProperties on ListItems would make this code work automatically in Alloy. Also, you didn't mention the actual error that occurs which identifies the missing applyProperties function as the culprit, so please add that before moving it to TIMOB.

JSON Source