Kalai Selvan Ravi
Kalai Selvan Ravi

Reputation: 2886

How to use ContainerList in lwuit 1.5?

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.

Upvotes: 0

Views: 1132

Answers (2)

Shai Almog
Shai Almog

Reputation: 52770

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).

Upvotes: 4

Nikhil
Nikhil

Reputation: 1309

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));

Upvotes: 0

Related Questions