Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AdapterView?

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?

like image 312
Student Student Avatar asked Feb 04 '13 05:02

Student Student


People also ask

What is Android AdapterView?

AdapterView is a ViewGroup that displays items loaded into an adapter. The most common type of adapter comes from an array-based data source.

What is difference between adapter and AdapterView?

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.

What is AdapterView in Java?

An AdapterView is a view whose children are determined by an Adapter . See ListView , GridView , Spinner and Gallery for commonly used subclasses of AdapterView.

What is an ArrayAdapter in Android?

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 .


1 Answers

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).

like image 154
Leonidos Avatar answered Oct 05 '22 16:10

Leonidos