Some hints that will help save you a lot of headache when working with data in a ListField
that could potentially change:
- When using a shared object (your
Vector
in this case) to house data that with both be updated and used by the ListField
, make sure that you synchronize whatever chunk of code is updating that Vector
. If you don't, you're likely to run into an IndexOutOfBounds Exception because the ListField
doesn't know how big the Vector
is while it's being updated.
- If what you are displaying is simple, the better solution would be to have some sort of bean that has the bare minimum necessary to display the row. You can expose some sort of synchronized
setItems()
call in your ListField
that will go through the Vector and just store a name (or whatever it is that you're displaying) and update the size so that no matter what you do to your Vector, the ListField
will always have good data.
In your case, you are correct in that you need to be calling the setSize(listItem.size());
to update the number of items in the list. If you use my second suggestion, what you could do to remove everything is simply call list.setItems(new Vector());
and that would set the size to 0 and also clear out the stored items. Alternatively, simply calling list.setSize(0);
will emulate the list being empty because it won't think it has anything to draw, so your "empty string" will be shown instead.
It could also be that there is a problem with your drawListRow()
method so it doesn't look like anything more than one row is being shown. If you post the code from it we can take a look at it and let you know if there are any potential problems.