コード例 #1
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   ListAdapter adapter = getAdapter();
   if (adapter != null && adapter instanceof HeaderViewGridAdapter) {
     ((HeaderViewGridAdapter) adapter).setNumColumns(getNumColumnsCompatible());
     ((HeaderViewGridAdapter) adapter).setRowHeight(getRowHeight());
   }
 }
コード例 #2
0
 @Override
 public void setAdapter(ListAdapter adapter) {
   if (mHeaderViewInfos.size() > 0) {
     HeaderViewGridAdapter hadapter = new HeaderViewGridAdapter(mHeaderViewInfos, adapter);
     int numColumns = getNumColumns();
     if (numColumns > 1) {
       hadapter.setNumColumns(numColumns);
     }
     super.setAdapter(hadapter);
   } else {
     super.setAdapter(adapter);
   }
 }
コード例 #3
0
 @Override
 public void setAdapter(ListAdapter adapter) {
   mOriginalAdapter = adapter;
   if (mHeaderViewInfos.size() > 0 || mFooterViewInfos.size() > 0) {
     HeaderViewGridAdapter headerViewGridAdapter =
         new HeaderViewGridAdapter(mHeaderViewInfos, mFooterViewInfos, adapter);
     int numColumns = getNumColumnsCompatible();
     if (numColumns > 1) {
       headerViewGridAdapter.setNumColumns(numColumns);
     }
     headerViewGridAdapter.setRowHeight(getRowHeight());
     super.setAdapter(headerViewGridAdapter);
   } else {
     super.setAdapter(adapter);
   }
 }
コード例 #4
0
  public void addFooterView(View v, Object data, boolean isSelectable) {
    ListAdapter mAdapter = getAdapter();
    if (mAdapter != null && !(mAdapter instanceof HeaderViewGridAdapter)) {
      throw new IllegalStateException(
          "Cannot add header view to grid -- setAdapter has already been called.");
    }

    ViewGroup.LayoutParams lyp = v.getLayoutParams();

    FixedViewInfo info = new FixedViewInfo();
    FrameLayout fl = new FullWidthFixedViewLayout(getContext());

    if (lyp != null) {
      v.setLayoutParams(new FrameLayout.LayoutParams(lyp.width, lyp.height));
      fl.setLayoutParams(new AbsListView.LayoutParams(lyp.width, lyp.height));
    }
    fl.addView(v);
    info.view = v;
    info.viewContainer = fl;
    info.data = data;
    info.isSelectable = isSelectable;
    mFooterViewInfos.add(info);

    if (mAdapter != null) {
      ((HeaderViewGridAdapter) mAdapter).notifyDataSetChanged();
    }
  }
コード例 #5
0
  /**
   * Add a fixed view to appear at the top of the grid. If addHeaderView is called more than once,
   * the views will appear in the order they were added. Views added using this call can take focus
   * if they want.
   *
   * <p>NOTE: Call this before calling setAdapter. This is so HeaderGridView can wrap the supplied
   * cursor with one that will also account for header views.
   *
   * @param v The view to add.
   * @param data Data to associate with this view
   * @param isSelectable whether the item is selectable
   */
  public void addHeaderView(View v, Object data, boolean isSelectable) {
    ListAdapter adapter = getAdapter();
    if (adapter != null && !(adapter instanceof HeaderViewGridAdapter)) {
      throw new IllegalStateException(
          "Cannot add header view to grid -- setAdapter has already been called.");
    }

    ViewGroup.LayoutParams lyp = v.getLayoutParams();

    FixedViewInfo info = new FixedViewInfo();
    FrameLayout fl = new FullWidthFixedViewLayout(getContext());

    if (lyp != null) {
      v.setLayoutParams(new FrameLayout.LayoutParams(lyp.width, lyp.height));
      fl.setLayoutParams(new LayoutParams(lyp.width, lyp.height));
    }
    fl.addView(v);
    info.view = v;
    info.viewContainer = fl;
    info.data = data;
    info.isSelectable = isSelectable;
    mHeaderViewInfos.add(info);
    // in the case of re-adding a header view, or adding one later onCallBackData,
    // we need to notify the observer
    if (adapter != null) {
      ((HeaderViewGridAdapter) adapter).notifyDataSetChanged();
    }
  }
コード例 #6
0
 @Override
 public void setNumColumns(int numColumns) {
   super.setNumColumns(numColumns);
   mNumColumns = numColumns;
   ListAdapter adapter = getAdapter();
   if (adapter != null && adapter instanceof HeaderViewGridAdapter) {
     ((HeaderViewGridAdapter) adapter).setNumColumns(numColumns);
   }
 }