Documents say:
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.
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?
AdapterView is a ViewGroup that displays items loaded into an adapter. The most common type of adapter comes from an array-based data source.
An Adapter is responsible for creating and binding data to views. An Adapter isn't an actual view, but instead produces them. An AdapterView is a ViewGroup that gets its child views from an Adapter . E.g. a ListView has a child view for each row in its list.
An AdapterView is a view whose children are determined by an Adapter . See ListView , GridView , Spinner and Gallery for commonly used subclasses of AdapterView.
android.widget.ArrayAdapter<T> You can use this adapter to provide views for an AdapterView , Returns a view for each object in a collection of data objects you provide, and can be used with list-based user interface widgets such as ListView or Spinner .
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
.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With