FileDocCategorySizeDatePackage
HeaderViewListAdapter.javaAPI DocAndroid 5.1 API8669Thu Mar 12 22:22:10 GMT 2015android.widget

HeaderViewListAdapter

public class HeaderViewListAdapter extends Object implements Filterable, WrapperListAdapter
ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects.

This is intended as a base class; you will probably not need to use this class directly in your own code.

Fields Summary
private final ListAdapter
mAdapter
ArrayList
mHeaderViewInfos
ArrayList
mFooterViewInfos
static final ArrayList
EMPTY_INFO_LIST
boolean
mAreAllFixedViewsSelectable
private final boolean
mIsFilterable
Constructors Summary
public HeaderViewListAdapter(ArrayList headerViewInfos, ArrayList footerViewInfos, ListAdapter adapter)


      
                                  
                                   
        mAdapter = adapter;
        mIsFilterable = adapter instanceof Filterable;

        if (headerViewInfos == null) {
            mHeaderViewInfos = EMPTY_INFO_LIST;
        } else {
            mHeaderViewInfos = headerViewInfos;
        }

        if (footerViewInfos == null) {
            mFooterViewInfos = EMPTY_INFO_LIST;
        } else {
            mFooterViewInfos = footerViewInfos;
        }

        mAreAllFixedViewsSelectable =
                areAllListInfosSelectable(mHeaderViewInfos)
                && areAllListInfosSelectable(mFooterViewInfos);
    
Methods Summary
public booleanareAllItemsEnabled()

        if (mAdapter != null) {
            return mAreAllFixedViewsSelectable && mAdapter.areAllItemsEnabled();
        } else {
            return true;
        }
    
private booleanareAllListInfosSelectable(java.util.ArrayList infos)

        if (infos != null) {
            for (ListView.FixedViewInfo info : infos) {
                if (!info.isSelectable) {
                    return false;
                }
            }
        }
        return true;
    
public intgetCount()

        if (mAdapter != null) {
            return getFootersCount() + getHeadersCount() + mAdapter.getCount();
        } else {
            return getFootersCount() + getHeadersCount();
        }
    
public FiltergetFilter()

        if (mIsFilterable) {
            return ((Filterable) mAdapter).getFilter();
        }
        return null;
    
public intgetFootersCount()

        return mFooterViewInfos.size();
    
public intgetHeadersCount()

        return mHeaderViewInfos.size();
    
public java.lang.ObjectgetItem(int position)

        // Header (negative positions will throw an IndexOutOfBoundsException)
        int numHeaders = getHeadersCount();
        if (position < numHeaders) {
            return mHeaderViewInfos.get(position).data;
        }

        // Adapter
        final int adjPosition = position - numHeaders;
        int adapterCount = 0;
        if (mAdapter != null) {
            adapterCount = mAdapter.getCount();
            if (adjPosition < adapterCount) {
                return mAdapter.getItem(adjPosition);
            }
        }

        // Footer (off-limits positions will throw an IndexOutOfBoundsException)
        return mFooterViewInfos.get(adjPosition - adapterCount).data;
    
public longgetItemId(int position)

        int numHeaders = getHeadersCount();
        if (mAdapter != null && position >= numHeaders) {
            int adjPosition = position - numHeaders;
            int adapterCount = mAdapter.getCount();
            if (adjPosition < adapterCount) {
                return mAdapter.getItemId(adjPosition);
            }
        }
        return -1;
    
public intgetItemViewType(int position)

        int numHeaders = getHeadersCount();
        if (mAdapter != null && position >= numHeaders) {
            int adjPosition = position - numHeaders;
            int adapterCount = mAdapter.getCount();
            if (adjPosition < adapterCount) {
                return mAdapter.getItemViewType(adjPosition);
            }
        }

        return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
    
public android.view.ViewgetView(int position, android.view.View convertView, android.view.ViewGroup parent)

        // Header (negative positions will throw an IndexOutOfBoundsException)
        int numHeaders = getHeadersCount();
        if (position < numHeaders) {
            return mHeaderViewInfos.get(position).view;
        }

        // Adapter
        final int adjPosition = position - numHeaders;
        int adapterCount = 0;
        if (mAdapter != null) {
            adapterCount = mAdapter.getCount();
            if (adjPosition < adapterCount) {
                return mAdapter.getView(adjPosition, convertView, parent);
            }
        }

        // Footer (off-limits positions will throw an IndexOutOfBoundsException)
        return mFooterViewInfos.get(adjPosition - adapterCount).view;
    
public intgetViewTypeCount()

        if (mAdapter != null) {
            return mAdapter.getViewTypeCount();
        }
        return 1;
    
public ListAdaptergetWrappedAdapter()

        return mAdapter;
    
public booleanhasStableIds()

        if (mAdapter != null) {
            return mAdapter.hasStableIds();
        }
        return false;
    
public booleanisEmpty()

        return mAdapter == null || mAdapter.isEmpty();
    
public booleanisEnabled(int position)

        // Header (negative positions will throw an IndexOutOfBoundsException)
        int numHeaders = getHeadersCount();
        if (position < numHeaders) {
            return mHeaderViewInfos.get(position).isSelectable;
        }

        // Adapter
        final int adjPosition = position - numHeaders;
        int adapterCount = 0;
        if (mAdapter != null) {
            adapterCount = mAdapter.getCount();
            if (adjPosition < adapterCount) {
                return mAdapter.isEnabled(adjPosition);
            }
        }

        // Footer (off-limits positions will throw an IndexOutOfBoundsException)
        return mFooterViewInfos.get(adjPosition - adapterCount).isSelectable;
    
public voidregisterDataSetObserver(android.database.DataSetObserver observer)

        if (mAdapter != null) {
            mAdapter.registerDataSetObserver(observer);
        }
    
public booleanremoveFooter(android.view.View v)

        for (int i = 0; i < mFooterViewInfos.size(); i++) {
            ListView.FixedViewInfo info = mFooterViewInfos.get(i);
            if (info.view == v) {
                mFooterViewInfos.remove(i);

                mAreAllFixedViewsSelectable =
                        areAllListInfosSelectable(mHeaderViewInfos)
                        && areAllListInfosSelectable(mFooterViewInfos);

                return true;
            }
        }

        return false;
    
public booleanremoveHeader(android.view.View v)

        for (int i = 0; i < mHeaderViewInfos.size(); i++) {
            ListView.FixedViewInfo info = mHeaderViewInfos.get(i);
            if (info.view == v) {
                mHeaderViewInfos.remove(i);

                mAreAllFixedViewsSelectable =
                        areAllListInfosSelectable(mHeaderViewInfos)
                        && areAllListInfosSelectable(mFooterViewInfos);

                return true;
            }
        }

        return false;
    
public voidunregisterDataSetObserver(android.database.DataSetObserver observer)

        if (mAdapter != null) {
            mAdapter.unregisterDataSetObserver(observer);
        }