When the content for your layout is dynamic or not pre-determined, you can use a layout that subclasses AdapterView to populate the layout with views at runtime. A subclass of the AdapterView class uses an Adapter to bind data to its layout.
但是大部分教程都是关于ListView
、GridView
、Spinner
和Gallery
的。
我希望直接从 AdapterView
扩展一个子类。我必须创建一个自定义 View ,它的内容取决于适配器。
我该怎么做,必须重写哪些方法?
最佳答案
首先,您应该绝对确定 AdapterView
是您想要的,因为并非所有“动态或非预定” View 都可以通过 AdapterView
实现。有时您最好创建扩展 ViewGroup
的 View 。
如果您想使用 AdapterView
,请查看 this really nice example . GitHub 上有很多带有适配器的自定义 View 。 Check out this one (extends ViewGroup
) .
关于安卓适配器 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14681022/