drawListRow 方法中索引未更新
我在 os 5.0 和 letter.my 中使用 Listfield,所有数据都来自 webservice 并将其显示在 listfield 中。在解析时间期间,一切都正常工作,并成功显示在 listfield 中。如果第一次我只有一条记录在行中显示它工作正常,但我单击我的 NextButtonfield
来更新 listfield ,我得到多个记录,并且 listfield 向我显示一条记录..
我进行了很多调试并遇到了一些问题..drawListRow 方法的索引未按 setSize(listItem.size());
递增。 listItem
是向量,它的更新成功取决于记录。
那么如何根据向量大小更新索引呢?或者如何在更新时删除所有行?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在处理
ListField
中可能发生变化的数据时,一些提示将帮助您避免很多的麻烦:Vector 在这种情况下)来容纳由
ListField
更新和使用的数据,请确保同步更新该Vector
的任何代码块。如果不这样做,您可能会遇到 IndexOutOfBounds 异常,因为ListField
在更新时不知道Vector
有多大。ListField
中公开某种同步的setItems()
调用,该调用将遍历 Vector 并仅存储名称(或您正在显示的任何内容)并更新大小,以便无论您对 Vector 执行什么操作,ListField
都将始终拥有良好的数据。在您的情况下,您是正确的,因为您需要调用
setSize(listItem.size());
来更新列表中的项目数。如果您使用我的第二个建议,则删除所有内容只需调用 list.setItems(new Vector()); 即可将大小设置为 0 并清除存储的项目。或者,只需调用list.setSize(0);
将模拟列表为空,因为它不会认为它有任何可绘制的内容,因此将显示“空字符串”。也可能是您的
drawListRow()
方法存在问题,因此看起来只显示了一行。如果您发布其中的代码,我们可以查看它并让您知道是否存在任何潜在问题。Some hints that will help save you a lot of headache when working with data in a
ListField
that could potentially change:Vector
in this case) to house data that with both be updated and used by theListField
, make sure that you synchronize whatever chunk of code is updating thatVector
. If you don't, you're likely to run into an IndexOutOfBounds Exception because theListField
doesn't know how big theVector
is while it's being updated.setItems()
call in yourListField
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, theListField
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 calllist.setItems(new Vector());
and that would set the size to 0 and also clear out the stored items. Alternatively, simply callinglist.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.从 这篇博客文章:
Found a solution from this blog article: