The native ListView is a optimized for very large lists. Instead of creating the views for each item, it reuses the same views when possible. This optimization makes it very difficult to customize the items.
CustomListView is an implementation of a list based on ScrollView.
CustomListView is suited for lists of up to 1000 or 2000 items.
Advantages of CustomListView:
- Each item is made of a Panel that can hold any views.
- Items can be modified at any time.
- It is possible to insert or remove items from any position.
- Each item can have a different height.
- Items height can be set automatically based on the text (using AddTextItem).
Using CustomListView is simple:
- First you should initialize the list and add it to a panel or activity.
- Then you should add items.
Each item is made of a panel that holds other views.
AddTextItem is a convenient utility to add items made of a single label.
The attached example creates two lists:
View attachment 41397
The first list is made of simple text items.
In the second list each item is created by loading another layout file.
A nice advantage of using a layout file to create the cell, is that it allows us to use anchors and designer script to create a flexible layout that changes based on the screen size. Rotate the device to landscape to see it.
This class depends on the JavaObject and StringUtils libraries.
V1.20 - Better designer support. Example code simplified.
V1.10 - Adds designer support. CustomListView can now be added with the visual designer. Add a CustomView and then set its CustomType property to CustomListView.