Description
When creating a ListView in a widget, it is not possible to add the templates as children of the widget.
Sample
The ListView is created as a Widget. XML code:
<Alloy>
<ListView id="list">
<ListSection>
<ListItem image:image="someimage.jpg" label:text="this is some text"/>
</ListSection>
</ListView>
</Alloy>
The Templates should be added in the index.xml:
<Alloy>
<Window>
<Widget src="listtemplate" defaultItemTemplate="template1">
<Templates>
<ItemTemplate name="template1" height="100">
<ImageView bindId="image" id="image"/>
<Label bindId="label" id="label1"/>
</ItemTemplate>
</Templates>
</Widget>
</Window>
</Alloy>
[~dcassenti] Can you please give us an example use case?
lib/customlist.js
var ListView = function(args) { this.view = Ti.UI.createListView(args); } ListView.prototype.addMeASectionPlease = function(items) { var section = Ti.UI.createListSection(); section.setItems(items); return this.view.appendSection(section); } ListView.prototype.getView = function() { return this.view; } exports.createListView = function(args) { return new ListView(args); };index.xml
index.js
$.addButton.addEventListener('click', function() { var items = [ {title: {text:'Foo'}, properties: {template:'template', backgroundColor: 'purple'}}, {title: {text:'Bar'}, properties: {template:'template'}}, {title: {text:'Baz'}, properties: {template:'template'}} ]; $.mylist.addMeASectionPlease(items); }) $.index.open();Closing, see ALOY-1102 for a solution