index not update in drawListRow method

256 views Asked by At

i m working with Listfield in os 5.0 and letter.my all data comes from webservice and display it in listfield .. everything work fine at first time during parsing time and display in listfield successfully .. if at the first time i have only one record to display in row it work fine but i click on my NextButtonfield to update listfield , i get more than one record and listfield show me one one record ..

i have debug alot and get some issue .. index of drawListRow method not incremented as setSize(listItem.size()); . listItem is vector and it update successfully depend on record .

so how to update index depend on vector size ? or how to remove all row at update time ?

2

There are 2 answers

0
Hitarth On

Found a solution from this blog article:

A working solution I found is to remove the ListField Control from its manager, set it to null and reinitialize it.

Not the best solution but currently the only way it is working for me:

Manager.delete(ListField);
ListField = null;
ListField = FillListWithItems();

Manager.add(ListField);
0
jprofitt On

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.