0

我在 os 5.0 和 letter.my 中使用 Listfield在行中显示它工作正常,但我点击我NextButtonfield的更新列表字段,我得到多条记录,列表字段显示一条记录..

我已经调试了很多并得到了一些问题.. drawListRow 方法的索引没有增加为setSize(listItem.size());listItem是向量,它更新成功取决于记录。

那么如何更新索引取决于向量大小?或者如何在更新时删除所有行?

4

2 回答 2

2

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.

于 2011-11-01T12:29:51.803 回答
0

从这篇博客文章中找到了解决方案:

我发现一个可行的解决方案是从其管理器中删除 ListField 控件,将其设置为 null 并重新初始化它。

不是最好的解决方案,但目前它是为我工作的唯一方法:

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

Manager.add(ListField);
于 2011-11-02T04:21:21.077 回答