Skip to main content

How to clear elements of List

1 reply [Last post]
ajay_kumar
Offline
Joined: 2008-06-26
Points: 0

hi everbody

i m using LWUIT tool for develop mobile application.but i m unable to clear all elements of List.
you have nay solution for this plz reply me soon

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15
Points: 0

FYI... the source for LWUIT is available at:
https://lwuit.dev.java.net/source/browse/lwuit/trunk/MIDP/LWUIT/src/com/...

There seems to be 2 ways of clearing all elements from the list.
1) get the model, from the model get the size, and then remove the item at an index (size) number of times.
ListModel model = uiList.getModel();
for(int i=model.getSize(); i>=0; --i)
model.removeItem(i);

2) replace the model with an empty one.

ListModel model = new YourModel();
uiList.setModel(model);

Next time try reading the source, it is faster than waiting for someone else to read it for you.

-Shawn