Android的适配器视图?适配器、视图、Android

2023-09-04 23:57:00 作者:把酒祝东风

Documents说:

当你的布局内容是动态还是不pre-确定,您   可以使用布局子类适配器视图来填充版面   有观点在运行时。该适配器视图类的子类使用一个   适配器将数据绑定到其布局。

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 微调图库

But most of tutorials are in about ListView,GridView,Spinner and Gallery.

我希望直接从适配器视图扩展子类。我要创建一个自定义视图,它的内容是依赖于一个适配器。

I'm looking to extend a subclass directly from AdapterView. I have to create a custom view that it's content is dependent to an adapter.

我怎么能做到这一点,什么方法都必须重写?

How can I do this, and what methods must be overridden?

推荐答案

首先,你应该绝对确保适配器视图是你想要的,因为不是所有的动态或没有pre-决定的意见可通过适配器视图实施。有时候,你最好创建扩展视图的ViewGroup

First, you should be absolutely sure that AdapterView is what you want, because not all "dynamic or not pre-determined" views can be implement via AdapterView. Sometimes you'd better create your view extending ViewGroup.

如果你想使用适配器视图,看看this非常好的例子的。有很多的自定义视图使用适配器在GitHub上。 看看这一个(扩展的ViewGroup )。

if you want to use AdapterView, take a look at this really nice example. There are a lot of custom views with adapter on GitHub. Check out this one (extends ViewGroup).