在 ArrayAdapter 和 SimpleAdapter 之间进行选择

发布于 2024-11-16 05:01:49 字数 399 浏览 10 评论 0原文

我想知道,对于我们如何在 ArrayAdapter 和 SimpleAdapter 之间进行选择,是否有任何指南。

对于每个列表项,它们将由多个 TextView 和 View 呈现,布局良好。我意识到我可以通过使用 ArrayAdapter 或 SimpleAdapter 来毫无问题地实现这两者。

有什么指导方针可以指导我们如何在其中进行选择吗?我的猜测是

  1. ArrayAdapter 使我们能够动态添加新项目,即使在列表显示期间也是如此。请注意,ArrayAdapter 有方法add
  2. SimpleAdapter 用于情况,一旦显示列表,就不能再添加新项目。

这是我们应该遵循的指导方针吗?

I was wondering, is there any guideline, on how we choose between ArrayAdapter and SimpleAdapter.

For every list item, they will be presented by several TextViews and Views, which is being layout nicely. I realize I can implement both without any problem, by either using ArrayAdapter or SimpleAdapter.

Is there any guideline, on how we choose among them? My guess is

  1. ArrayAdapter enables us to add in new item dynamically, even after the list is being shown during that time. Note that, ArrayAdapter is having method add.
  2. SimpleAdapter is used for case, once the list is being shown, there are no more new item can be added.

Is this the guideline we should follow?

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

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

发布评论

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

评论(2

触ぅ动初心 2024-11-23 05:01:49

就我个人而言,我不认为 SimpleAdapter 非常有用。您的模型数据很少自然地存在于“MapsArrayList”中,并且仅仅为了将其放入适配器而复制内容是浪费的。

我会使用 ArrayAdapter (如果我的模型数据是对象数组)或 BaseAdapter (如果我的模型数据是其他内存中数据结构)。

Personally, I don't find SimpleAdapter terribly useful. Your model data is rarely naturally in "an ArrayList of Maps", and it is wasteful to be copying stuff around just to get it in an adapter.

I would either use ArrayAdapter (if my model data is an array of objects) or BaseAdapter (if my model data is some other in-memory data structure).

じ违心 2024-11-23 05:01:49

数组适配器可用于从动态数组填充列表视图,而简单适配器用于从哈希映射或关联数组填充列表视图,因为数组适配器中没有构造函数可以采用键数组和一个 int 数组,它是我们要填充数据的布局 id。

Array Adapter could be used to fill out a list view from a dynamic array while the simple adapter is used to fill the list view from a Hash Map or Associative array because there is no constructor in the Array adapter that could take An array of keys and an array of int which is the layout ids we want to fill the data in.

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