Search code examples
ioslistviewappceleratorlistviewitemappcelerator-titanium

Appcelerator : animate the backgroundColor of a listview item


I'm trying to animate the backgroundColor property of a listview item children.

This is the code

var itemToUpdate = myListView.getSections();
itemToUpdate = itemToUpdate[0].getItemAt(myPos);
//itemToUpdate.child_to_update.backgroundColor = myColor; //this works , but without animation
itemToUpdate.child_to_update.animate({
    backgroundColor : myColor,
    duration : 450
});
myListView.sections[0].updateItemAt(myPos , itemToUpdate);

Solution

  • The method Ti.UI.ListSection.getItemAt() gets you a ListDataItem. This object does not hold references to the actual views, but to the data used to generated the views using the ListView ItemTemplates you have defined. This is great for performance, but it means you cannot directly manipulate the views and use a method like animate().

    TL;DR What you want is not possible using ListView. Consider using TableView instead.