FileDocCategorySizeDatePackage
SectionedListAdapter.javaAPI DocAndroid 5.1 API5250Thu Mar 12 22:22:40 GMT 2015com.android.documentsui

SectionedListAdapter

public class SectionedListAdapter extends android.widget.BaseAdapter
Adapter that combines multiple adapters as sections, asking each section to provide a header, and correctly handling item types across child adapters.

Fields Summary
private ArrayList
mSections
Constructors Summary
Methods Summary
public voidaddSection(com.android.documentsui.SectionedListAdapter$SectionAdapter adapter)
After mutating sections, you must {@link AdapterView#setAdapter(android.widget.Adapter)} to correctly recount view types.

        mSections.add(adapter);
        notifyDataSetChanged();
    
public booleanareAllItemsEnabled()

        return false;
    
public voidclearSections()


         
             
    

       
        mSections.clear();
        notifyDataSetChanged();
    
public intgetCount()

        int count = 0;
        final int size = mSections.size();
        for (int i = 0; i < size; i++) {
            count += mSections.get(i).getCount() + 1;
        }
        return count;
    
public java.lang.ObjectgetItem(int position)

        final int size = mSections.size();
        for (int i = 0; i < size; i++) {
            final SectionAdapter section = mSections.get(i);
            final int sectionSize = section.getCount() + 1;

            // Check if position inside this section
            if (position == 0) {
                return section;
            } else if (position < sectionSize) {
                return section.getItem(position - 1);
            }

            // Otherwise jump into next section
            position -= sectionSize;
        }
        throw new IllegalStateException("Unknown position " + position);
    
public longgetItemId(int position)

        return position;
    
public intgetItemViewType(int position)

        int type = 1;
        final int size = mSections.size();
        for (int i = 0; i < size; i++) {
            final SectionAdapter section = mSections.get(i);
            final int sectionSize = section.getCount() + 1;

            // Check if position inside this section
            if (position == 0) {
                return 0;
            } else if (position < sectionSize) {
                return type + section.getItemViewType(position - 1);
            }

            // Otherwise jump into next section
            position -= sectionSize;
            type += section.getViewTypeCount();
        }
        throw new IllegalStateException("Unknown position " + position);
    
public android.view.ViewgetView(int position, android.view.View convertView, android.view.ViewGroup parent)

        final int size = mSections.size();
        for (int i = 0; i < size; i++) {
            final SectionAdapter section = mSections.get(i);
            final int sectionSize = section.getCount() + 1;

            // Check if position inside this section
            if (position == 0) {
                return section.getHeaderView(convertView, parent);
            } else if (position < sectionSize) {
                return section.getView(position - 1, convertView, parent);
            }

            // Otherwise jump into next section
            position -= sectionSize;
        }
        throw new IllegalStateException("Unknown position " + position);
    
public intgetViewTypeCount()

        int count = 1;
        final int size = mSections.size();
        for (int i = 0; i < size; i++) {
            count += mSections.get(i).getViewTypeCount();
        }
        return count;
    
public booleanisEnabled(int position)

        final int size = mSections.size();
        for (int i = 0; i < size; i++) {
            final SectionAdapter section = mSections.get(i);
            final int sectionSize = section.getCount() + 1;

            // Check if position inside this section
            if (position == 0) {
                return false;
            } else if (position < sectionSize) {
                return section.isEnabled(position - 1);
            }

            // Otherwise jump into next section
            position -= sectionSize;
        }
        throw new IllegalStateException("Unknown position " + position);