Android Adapters and AdapterViews
Some GUI Views can have associated with them data that feeds their display.
In this case they will most often use Adapters(binds data to view) and AdapterViews( populated with Adapter assistance)
Adapter?
-
An Adapter can act as a bridget wetween an AdapterView and a data source that feeds it.
-
Useful methods to do this include:
abstract int getCount() How many items are in the data set represented by this Adapter.abstract Object getItem(int position) Get the data item associated with the specified position in the data set.abstract long getItemId(int position) Get the row id associated with the specified position in the list.abstract int getItemViewType(int position) Get the type of View that will be created by getView(int, View, ViewGroup) for the specified item.abstract View getView(int position, View convertView, ViewGroup parent) Get a View that displays the data at the specified position in the data set.abstract int getViewTypeCount() Returns the number of types of Views that will be created by getView(int, View, ViewGroup).
abstract boolean hasStableIds() Indicates whether the item ids are stable across changes to the underlying data.abstract boolean isEmpty() abstract void registerDataSetObserver(DataSetObserver observer) Register an observer that is called when changes happen to the data used by this adapter.abstract void unregisterDataSetObserver(DataSetObserver observer) Unregister an observer that has previously been registered with this adapter via registerDataSetObserver(DataSetObserver).
Examples of Adapters
-
BaseAdapter (see our Gallery example to see its use)
-
subclasses of BaseAdapter
ListAdapter, ArrayAdapter, CursorAdapter, SpinnerAdapter,
-
subclasses of BaseAdapter
AdapterView?
-
Displays data "connected/bound" to it from Adapter
-
Examples of AdpaterView classes
Data source (e.g. Images) |
----------Adapter>>>>>> |
AdapterView (e.g. Gallery) |