Android ListAdapter

ListAdapter is an interface that's used to bind a ListView to its data.

This inteface resides inside the android.widget package:

package android.widget;

It derives from android.widget.Adapter, an interface that contains several signatures to be implemented by it's implementers.

public interface ListAdapter extends Adapter {}

Majority of the times that data needs to come from a Cursor object, however it's not mandatory. ListView can display any data as long as it's contained in a ListAdapter.

Methods in ListAdapter

This interface has only two method signatures. The rest it inherits from the Adapter interface.

  1. public boolean areAllItems Enabled() : This method clearly returns a boolean. This boolean indicates whether all items in this adapter are enabled. If true then it means that all the items in the List can be selected and clicked.

  2. isEnabled(int position): This method takes the position of the item. It will return true if that item(at that position) is not a separator. Remember separators are list items that can neither be clicked nor selected.

Classes that Implement ListAdapter

ListAdapter is an interface that's implemented by 7 classes and one interface.

All these are defined inside the android.widget package:

No. Method Definition
1. BaseAdapter A super class of common implementations for an android.widget.Adapter interface.It implements both ListAdapter and SpinnerAdapter interfaces.
2. ArrayAdapter A BaseAdapter child which uses an array of arbitrary objects as data source.
3. CursorAdapter An abstract BaseAdapter child used to expose data from android.database.Cursor to a ListView.
4. ResourceCursorAdapter An abtract CursorAdapter child that provides an easy way to create views defined in an xml file.
5. SimpleAdapter An easy BaseAdapter child used to map static data to views defined in an XML file.
6. SimpleCursorAdapter A ResourceCursorAdapter child that provides an easy way to map columns from a cursor to TextViews or ImageViews defined in an XML file.
7. WrapperListAdapter This is an interface that wraps another list adapter.
8. HeaderViewListAdapter This is an indirect list adapter used with a ListView when the ListView has header views.

Other Adapter Types

Let's look at some of the available adapter subclasses.

Android PagerAdapter Tutorial and Examples.

Normally you use PagerAdapters with ViewPager. ViewPager you know allows us swipe through pages.

Well PagerAdapter acts as the base class for providing the adapter to populate pages inside of that ViewPager.

BaseAdapter as the name suggests BaseAdapter is a base adapter, or super adapter. An adapter is a class that acts as a bridge between an adapterview and the underlying data source.

ArrayAdapter is concrete class that derives from the BaseAdapter and is backed by an array of arbitrary objects.

ArrayAdapter requires us to pass a single TextView as a resource as the layout. This is for simple layouts where you don't have to create a custom adapter.

For complex layouts...

SpinnerAdapter is an interface that binds android.widget.Spinner to its data.

This interface lives inside the android.widget package:

package android.widget;

Like the ListAdapter, this interface derives majority of its methods from the android.widget.Adapter interface.


How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:


What do You Think

Previous Post Next Post