Titanium api: ListView
访问量: 2971
refer to: http://docs.appcelerator.com/titanium/latest/#!/guide/ListViews
and : http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.ListView (新手小心这个doc ,会引起奇怪的undefined function ... )
以及: http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_ListView_Guide
概念: ListView 与TableView 很像。 在大数据量下,建议使用ListView, 因为它调用的是 native code ,而不是 Ti-SDK (managed by the platform, but not the application)
我们无法直接访问 ListView的某个row, 而是需要定义Template来操作它。 每个row ( ListItem) 都可以有自己的Template + ListItemData.
下面是重要概念:
ListItem. 一个row. 根据item template + data item生成。
ItemTemplate. 定义了ListItem的展现形式。
ListDataItem. 给ItemTemplate使用的 data item, 用来展现具体的数据。( A list data item is a JavaScript object that contains the data you want to display in the list. The data is applied to a template to create a list item. )
ListSection. 用来包含多个 ListItem ( A list section is a view object that is used to manipulate and organize list items contained within it.)
ListView. 用来包含多个ListSection. ( A list view is a view object that is used to manipulate and organize list sections contained within it. )
可以使用 Titanium SDK 的 createListItem 这样的方式来创建,也可以使用 Alloy XML来创建。
注意: ListView 只能在Android 和 IOS下使用,无法在 MobileWeb中使用。会报错。
<Alloy>
<Window class="container">
<ListView id="elementsList">
<ListSection name="elements">
<ListItem title="Hydrogen"/>
<ListItem title="Helium"/>
<ListItem title="Lithium"/>
<ListItem title="Beryllium"/>
<ListItem title="Boron"/>
<ListItem title="Carbon"/>
<ListItem title="Nitrogen"/>
<ListItem title="Oxygen"/>
<!-- Abbreviated... -->
</ListSection>
</ListView>
</Window>
</Alloy>