FileDocCategorySizeDatePackage
ColumnAdapter.javaAPI DocAndroid 5.1 API4291Thu Mar 12 22:22:40 GMT 2015com.android.documentsui

ColumnAdapter

public class ColumnAdapter extends android.widget.BaseAdapter
Adapter that wraps an existing adapter, presenting its contents in multiple equally-sized horizontal columns.

Fields Summary
private final android.widget.ListAdapter
mWrapped
private final OnItemClickListener
mListener
private int
mColumns
private View.OnClickListener
mItemListener
Constructors Summary
public ColumnAdapter(android.widget.ListAdapter wrapped, OnItemClickListener listener)


       
             
    

         
        mWrapped = Preconditions.checkNotNull(wrapped);
        mListener = Preconditions.checkNotNull(listener);

        if (!wrapped.areAllItemsEnabled()) {
            throw new IllegalStateException("All items must be enabled");
        }
        if (wrapped.getViewTypeCount() > 1) {
            throw new IllegalStateException("All items must be identical");
        }
    
Methods Summary
public intgetCount()


    
       
        return (mWrapped.getCount() + mColumns - 1) / mColumns;
    
public java.lang.ObjectgetItem(int position)

        return position;
    
public longgetItemId(int position)

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

        if (convertView == null) {
            convertView = new LinearLayout(parent.getContext());
        }

        final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                0, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.weight = 1f / mColumns;

        final LinearLayout row = (LinearLayout) convertView;
        final int first = position * mColumns;
        final int last = mWrapped.getCount() - 1;

        for (int i = 0; i < mColumns; i++) {
            View convertItem = null;
            if (i < row.getChildCount()) {
                convertItem = row.getChildAt(i);
            }

            final int pos = first + i;
            final int validPos = Math.min(pos, last);
            final View item = mWrapped.getView(validPos, convertItem, row);
            item.setTag(validPos);
            item.setOnClickListener(mItemListener);
            item.setFocusable(true);

            if (pos == validPos) {
                item.setVisibility(View.VISIBLE);
            } else {
                item.setVisibility(View.INVISIBLE);
            }

            if (convertItem == null) {
                row.addView(item, params);
            }
        }

        return convertView;
    
public static voidprepare(android.widget.ListView list)

        list.setItemsCanFocus(true);
    
public voidregisterDataSetObserver(android.database.DataSetObserver observer)

        super.registerDataSetObserver(observer);
        mWrapped.registerDataSetObserver(observer);
    
public voidsetColumns(int columns)

        mColumns = columns;
        notifyDataSetChanged();
    
public voidunregisterDataSetObserver(android.database.DataSetObserver observer)

        super.unregisterDataSetObserver(observer);
        mWrapped.unregisterDataSetObserver(observer);