FileDocCategorySizeDatePackage
HeaderViewListAdapter.javaAPI DocAndroid 1.5 API7863Wed May 06 22:41:56 BST 2009android.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 ListAdapter
mAdapter
ArrayList
mHeaderViewInfos
ArrayList
mFooterViewInfos
boolean
mAreAllFixedViewsSelectable
private boolean
mIsFilterable
Constructors Summary
public HeaderViewListAdapter(ArrayList headerViewInfos, ArrayList footerViewInfos, ListAdapter adapter)

        mAdapter = adapter;
        mIsFilterable = adapter instanceof Filterable;

        mHeaderViewInfos = headerViewInfos;
        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 == null ? 0 : mFooterViewInfos.size();
    
public intgetHeadersCount()

        return mHeaderViewInfos == null ? 0 : mHeaderViewInfos.size();
    
public java.lang.ObjectgetItem(int position)

        int numHeaders = getHeadersCount();
        if (mAdapter != null && position >= numHeaders) {
            int adjPosition = position - numHeaders;
            int adapterCount = mAdapter.getCount();
            if (adjPosition >= adapterCount && mFooterViewInfos != null) {
                return mFooterViewInfos.get(adjPosition - adapterCount).data;
            } else {
                return mAdapter.getItem(adjPosition);
            }
        } else if (position < numHeaders && mHeaderViewInfos != null) {
            return mHeaderViewInfos.get(position).data;
        }
        return null;
    
public longgetItemId(int position)

        int numHeaders = getHeadersCount();
        if (mAdapter != null && position >= numHeaders) {
            int adjPosition = position - numHeaders;
            int adapterCnt = mAdapter.getCount();
            if (adjPosition < adapterCnt) {
                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)

        int numHeaders = getHeadersCount();
        if (mAdapter != null && position >= numHeaders) {
            int adjPosition = position - numHeaders;
            int adapterCount = mAdapter.getCount();
            if (adjPosition >= adapterCount) {
                if (mFooterViewInfos != null) {
                    return mFooterViewInfos.get(adjPosition - adapterCount).view;
                }
            } else {
                return mAdapter.getView(adjPosition, convertView, parent);
            }
        } else if (position < numHeaders) {
            return mHeaderViewInfos.get(position).view;
        }
        return null;
    
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)

        int numHeaders = getHeadersCount();
        if (mAdapter != null && position >= numHeaders) {
            int adjPosition = position - numHeaders;
            int adapterCount = mAdapter.getCount();
            if (adjPosition >= adapterCount && mFooterViewInfos != null) {
                return mFooterViewInfos.get(adjPosition - adapterCount).isSelectable;
            } else {
                return mAdapter.isEnabled(adjPosition);
            }
        } else if (position < numHeaders && mHeaderViewInfos != null) {
            return mHeaderViewInfos.get(position).isSelectable;
        }
        return true;
    
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);
        }