使用 ArrayAdapter 在 ListView 中自定义行视图

发布于 2024-12-08 16:16:12 字数 434 浏览 0 评论 0原文

我有一个带有重写 ArrayAdapter 的 listView 。中包含一个ArrayList。对象 Order 可以具有以下状态:

  • NEW
  • READ
  • ACCEPTED
  • CANCELED

根据订单的状态,我会膨胀不同的布局并用 getView 方法中的值填充它并作为 View 返回。订单每分钟都会与服务器同步。这一切都像它应该的那样工作。如果有新订单出现,则会将其插入到 ArrayList 中,并调用 NotifyDataSetChange 并更新 listView。但是,由于某种原因,列表中的某些现有项目更改了其布局(状态未更改,在日志中检查)。每次调用 NotifyDataSetChanged 时都会发生这种情况,并且我在这种行为中看不到任何逻辑或任何内容。有谁知道为什么会发生这种情况?

谢谢, 菲利普

I have a listView with an overriden ArrayAdapter. In contains an ArrayList. The object Order can have following states:

  • NEW
  • READ
  • ACCEPTED
  • CANCELLED

Depending on the state of the order I inflate a different Layout and fill it with the values in the getView method and return as View. Orders are being synchronized with the server every minute. This works all like it should. If a new Order comes, it is inserted into the ArrayList and NotifyDataSetChange is called and the listView is updated. However, for some reason, some of the existing items in the list change their layout (the state is not changed, checked in the logs). This happens everytime NotifyDataSetChanged is called and I don't see any logic or anything in this behavior. Does anyone know why is this happening?

Thanks,
Filip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2024-12-15 16:16:12

我成功了。我认为问题是我从 ArrayAdapter 扩展而来,它在构造函数中接收 ROW 视图的视图资源 ID。然后将其交给 getView 方法。我正在使用一些教程,并且在那里测试了convertView是否为NULL。如果是的话我会夸大一个新的布局。然后我用我的价值观填充它。如果没有,我只是用值填充convertView。我想如果 ConvertView 不为空,它包含传递给 CustomArrayAdapter 构造函数的膨胀布局,因此更改了行的布局。我能说对吗?

I got it working. I think the problem was that I extended from the ArrayAdapter and it receives the View resource ID for the ROW view in the constructor. This is than given to the getView method. I was working with some tutorial and the convertView was tested there if it's NULL. If it was I inflated a new layout. Than I filled it with my values. If not, I just filled the convertView with the values. I supposed if the convertView wasn't null, it contained the inflated layout passed to the constructor of the CustomArrayAdapter and therefore changed the layout of the rows. Can I be right?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文