Adapter 和 AdapterView 之间的契约

发布于 2024-09-14 00:39:52 字数 396 浏览 10 评论 0原文

是否有某个地方描述了 Adapter 和 AdapterView 之间或 ListView 和 ListViewAdapter 之间的约定。

我正在尝试创建自己的 ListView 适配器。我不清楚方法调用的顺序,也不清楚谁可能调用这些方法。

似乎有几种重叠的方法。

  • getItem 返回一个数据对象,但是 你不知道类型。
  • getItemViewType 返回一个整数。整数由谁决定?他们是吗 在某处定义?用户定义?
  • getView

getView 似乎是唯一真正重要的。可能涉及哪些其他代码会尝试对返回的数据和返回的视图执行某些操作?如果两者的类型都不知道,其他代码如何知道如何将数据分配给视图?

对设计的一般解释会很有帮助。

Is there some place which describes the contract between Adapter and AdapterView, or between ListView and ListViewAdapter.

I'm trying to create my own ListView Adapter. It is not clear to me the sequence of method invocations nor who maybe calling these methods.

There appear to be several overlapping methods.

  • getItem returns a data object, but
    you don't know the type.
  • getItemViewType returns an integer. Who determines the integer? Are they
    defined somewhere? Userdefined?
  • getView

getView seems to be the only one that really matters. What other code maybe involved that would try to do something with the returned data and returned view? How can this other code know how to assign the data to the view if the type of neither is known?

A general explanation of the design would be helpful.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文