My list having variable length list items. ContainerList supports variable length list items. When I explored it on internet, I can't find any samples for ContainerList. Give me a sample piece of code to work on ContainerList.
-
Use a List, it will work for what you want to do – Mun0n Jun 25 '12 at 15:32
-
List won't support variable length list items. – Kalai Selvan Ravi Jun 25 '12 at 15:33
-
sure? wgat do you want to mean witj "variable lenght"? – Mun0n Jun 25 '12 at 17:57
-
I am having one list item as container. One list item container having 5 components, second list item having 3 components and the third list item having 4 components. When I see the output, there is a long space between second and third list item because list takes the maximum size list item as the default size for all list items. To avoid that, I need to use ContainerList. – Kalai Selvan Ravi Jun 26 '12 at 04:52
2 Answers
LWUIT demo contains a ContainerList sample in the Scroll demo.
There is also an explanation in our blog http://codenameone.blogspot.com/
Generally ContainerList is a drop-in replacement for list, just replace the usage of List with ContainerList and it should work pretty seamlessly (albeit slower).

- 51,749
- 5
- 35
- 65
Try this:
Vector variableLengthVector = new Vector();
variableLengthVector.clear();
for(int i=0;i< variableLengthStringArray.length;i++)
{
variableLengthVector.add(variableLengthStringArray[i]);
}
List myListToBeDisplaye = new List(variableLengthVector);
variableLengthStringArray--> It contains the items that you wish to show in your list.
So whenever you want to display a list , just populate a vector and initialize your list with that vector. Ensure, that you clear that vector or re initialize the vector before populating it.
Now, simply paste your list on a form or wherever you wish to display it..
Ok, you can find stuff about containerList here:
http://lwuit.java.net/nonav/javadocs/com/sun/lwuit/list/ContainerList.html
You can use a container list like this:
ContainerList abc = new ContainerList(new DefaultListModel(variableLengthVector));

- 1,279
- 2
- 23
- 43
-
No Nikhil. My single list item having 5 components like 2 Labels, 1 TextArea and 2 Images. How can I use Vector in this situation. – Kalai Selvan Ravi Jun 26 '12 at 05:53