ITEM_VIEW_TYPE_HEADER_OR_FOOTER源码实例Demo

android.widget.AdapterView#ITEM_VIEW_TYPE_HEADER_OR_FOOTER源码实例Demo

下面列出了android.widget.AdapterView#ITEM_VIEW_TYPE_HEADER_OR_FOOTER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BigApp_WordPress_Android   文件: HeaderGridView.java
@Override
public int getItemViewType(int position) {
    int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }
    if (mAdapter != null && position >= numHeadersAndPlaceholders) {
        int adjPosition = position - numHeadersAndPlaceholders;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        }
    }
    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
源代码2 项目: HeartbeatFixerForGCM   文件: HeaderGridView.java
@Override
public int getItemViewType(int position) {
    int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }
    if (mAdapter != null && position >= numHeadersAndPlaceholders) {
        int adjPosition = position - numHeadersAndPlaceholders;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        }
    }
    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
源代码3 项目: MutiPhotoChoser   文件: HeaderGridView.java
@Override
public int getItemViewType(int position) {
    int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }
    if (mAdapter != null && position >= numHeadersAndPlaceholders) {
        int adjPosition = position - numHeadersAndPlaceholders;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        }
    }

    if (position >= (mAdapter == null ? 0 : mAdapter.getCount()) + getHeadersCount() * mNumColumns && position % mNumColumns != 0) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }

    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
@Override
public int getItemViewType(int position) {
    int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }
    if (mAdapter != null && position >= numHeadersAndPlaceholders && position < numHeadersAndPlaceholders + mAdapter.getCount() + (mNumColumns - (mAdapter.getCount() % mNumColumns))) {
        int adjPosition = position - numHeadersAndPlaceholders;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        } else if (adapterCount != 0 && mNumColumns != 1) {
            return mAdapter.getItemViewType(adapterCount - 1);
        }
    }
    int numFootersAndPlaceholders = getFootersCount() * mNumColumns;
    if (mAdapter != null && position < numHeadersAndPlaceholders + mAdapter.getCount() + numFootersAndPlaceholders) {
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }

    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
源代码5 项目: AcDisplay   文件: HeaderGridView.java
@Override
public int getItemViewType(int position) {
    int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }
    if (mAdapter != null && position >= numHeadersAndPlaceholders) {
        int adjPosition = position - numHeadersAndPlaceholders;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        }
    }
    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
源代码6 项目: AnimatedGridView   文件: HeaderGridView.java
@Override
public int getItemViewType(int position) {
    int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }
    if (mAdapter != null && position >= numHeadersAndPlaceholders) {
        int adjPosition = position - numHeadersAndPlaceholders;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        }
    }

    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
源代码7 项目: HeadsUp   文件: HeaderGridView.java
@Override
public int getItemViewType(int position) {
    int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) {
        // Placeholders get the last view type number
        return mAdapter != null ? mAdapter.getViewTypeCount() : 1;
    }
    if (mAdapter != null && position >= numHeadersAndPlaceholders) {
        int adjPosition = position - numHeadersAndPlaceholders;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        }
    }
    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
public int getItemViewType(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;
}
 
@Override
public int getItemViewType(int position) {
    int mHeadersCount = getHeadersCount();
    if (null != mAdapter) {
        int itemCount = mAdapter.getItemCount();
        if (position < mHeadersCount) {
            //current itemType is Header
            mHeaderViewType = TYPE_HEADER_VIEW + position;
            mHeaderViewTypes.add(mHeaderViewType);
            return mHeaderViewType;
        } else if (position >= mHeadersCount && position < mHeadersCount + itemCount) {
            //current itemType is item defined by user
            int itemViewType = mAdapter.getItemViewType(position - mHeadersCount);
            if (itemViewType <= TYPE_HEADER_VIEW + mHeadersCount) {
                throw new IllegalArgumentException("your adapter's return value of " +
                        "getItemViewType() must > (Integer.MinValue + your headersCount)");
            }
            return itemViewType;
        } else {
            //current itemType is Footer
            int mFooterViewType = TYPE_FOOTER_VIEW + position - itemCount;
            mFooterViewTypes.add(mFooterViewType);
            return mFooterViewType;
        }
    } else {
        return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
    }
}
 
源代码10 项目: ProjectX   文件: HeaderFooterViewListAdapter.java
@Override
public int getItemViewType(int position) {
    int numHeaders = getHeaderItemsCount() + getHeaderViewsCount();
    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;
}
 
源代码11 项目: Klyph   文件: HeaderViewListAdapter.java
public int getItemViewType(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;
}
 
源代码12 项目: UltimateAndroid   文件: HeaderViewListAdapter.java
public int getItemViewType(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;
}
 
源代码13 项目: PagingGridView   文件: FooterViewGridAdapter.java
public int getItemViewType(int position) {
    if (mAdapter != null) {
        int adjPosition = position;
        int adapterCount = mAdapter.getCount();
        if (adjPosition < adapterCount) {
            return mAdapter.getItemViewType(adjPosition);
        }
    }

    return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
}
 
源代码14 项目: PullToRefreshLibrary   文件: ExtendableListView.java
/**
 * Add a view as a child and make sure it is measured (if necessary) and
 * positioned properly.
 * 
 * @param child
 *            The view to add
 * @param position
 *            The position of this child
 * @param y
 *            The y position relative to which this view will be positioned
 * @param flowDown
 *            If true, align top edge to y. If false, align bottom edge to
 *            y.
 * @param selected
 *            Is this position selected?
 * @param recycled
 *            Has this view been pulled from the recycle bin? If so it does
 *            not need to be remeasured.
 */
private void setupChild(View child, int position, int y, boolean flowDown,
		boolean selected, boolean recycled) {
	final boolean isSelected = false; // TODO : selected &&
										// shouldShowSelector();
	final boolean updateChildSelected = isSelected != child.isSelected();
	final int mode = mTouchMode;
	final boolean isPressed = mode > TOUCH_MODE_DOWN
			&& mode < TOUCH_MODE_SCROLLING && mMotionPosition == position;
	final boolean updateChildPressed = isPressed != child.isPressed();
	final boolean needToMeasure = !recycled || updateChildSelected
			|| child.isLayoutRequested();

	int itemViewType = mAdapter.getItemViewType(position);

	LayoutParams layoutParams;
	if (itemViewType == ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
		layoutParams = generateWrapperLayoutParams(child);
	} else {
		layoutParams = generateChildLayoutParams(child);
	}

	layoutParams.viewType = itemViewType;
	layoutParams.position = position;

	if (recycled
			|| (layoutParams.recycledHeaderFooter && layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
		if (DBG)
			Log.d(TAG, "setupChild attachViewToParent position:" + position);
		attachViewToParent(child, flowDown ? -1 : 0, layoutParams);
	} else {
		if (DBG)
			Log.d(TAG, "setupChild addViewInLayout position:" + position);
		if (layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
			layoutParams.recycledHeaderFooter = true;
		}
		addViewInLayout(child, flowDown ? -1 : 0, layoutParams, true);
	}

	if (updateChildSelected) {
		child.setSelected(isSelected);
	}

	if (updateChildPressed) {
		child.setPressed(isPressed);
	}

	if (needToMeasure) {
		if (DBG)
			Log.d(TAG, "setupChild onMeasureChild position:" + position);
		onMeasureChild(child, layoutParams);
	} else {
		if (DBG)
			Log.d(TAG, "setupChild cleanupLayoutState position:" + position);
		cleanupLayoutState(child);
	}

	final int w = child.getMeasuredWidth();
	final int h = child.getMeasuredHeight();
	final int childTop = flowDown ? y : y - h;

	if (DBG) {
		Log.d(TAG, "setupChild position:" + position + " h:" + h + " w:"
				+ w);
	}

	final int childrenLeft = getChildLeft(position);

	if (needToMeasure) {
		final int childRight = childrenLeft + w;
		final int childBottom = childTop + h;
		onLayoutChild(child, position, flowDown, childrenLeft, childTop,
				childRight, childBottom);
	} else {
		onOffsetChild(child, position, flowDown, childrenLeft, childTop);
	}

}
 
源代码15 项目: UltimateAndroid   文件: ExtendableListView.java
/**
 * Add a view as a child and make sure it is measured (if necessary) and
 * positioned properly.
 *
 * @param child    The view to add
 * @param position The position of this child
 * @param y        The y position relative to which this view will be positioned
 * @param flowDown If true, align top edge to y. If false, align bottom
 *                 edge to y.
 * @param selected Is this position selected?
 * @param recycled Has this view been pulled from the recycle bin? If so it
 *                 does not need to be remeasured.
 */
private void setupChild(View child, int position, int y, boolean flowDown,
                        boolean selected, boolean recycled) {
    final boolean isSelected = false; // TODO : selected && shouldShowSelector();
    final boolean updateChildSelected = isSelected != child.isSelected();
    final int mode = mTouchMode;
    final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLLING &&
            mMotionPosition == position;
    final boolean updateChildPressed = isPressed != child.isPressed();
    final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

    int itemViewType = mAdapter.getItemViewType(position);

    LayoutParams layoutParams;
    if (itemViewType == ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
        layoutParams = generateWrapperLayoutParams(child);
    }
    else {
        layoutParams = generateChildLayoutParams(child);
    }

    layoutParams.viewType = itemViewType;
    layoutParams.position = position;

    if (recycled || (layoutParams.recycledHeaderFooter &&
            layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
        if (DBG) Log.d(TAG, "setupChild attachViewToParent position:" + position);
        attachViewToParent(child, flowDown ? -1 : 0, layoutParams);
    }
    else {
        if (DBG) Log.d(TAG, "setupChild addViewInLayout position:" + position);
        if (layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
            layoutParams.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, layoutParams, true);
    }

    if (updateChildSelected) {
        child.setSelected(isSelected);
    }

    if (updateChildPressed) {
        child.setPressed(isPressed);
    }

    if (needToMeasure) {
        if (DBG) Log.d(TAG, "setupChild onMeasureChild position:" + position);
        onMeasureChild(child, layoutParams);
    }
    else {
        if (DBG) Log.d(TAG, "setupChild cleanupLayoutState position:" + position);
        cleanupLayoutState(child);
    }

    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();
    final int childTop = flowDown ? y : y - h;

    if (DBG) {
        Log.d(TAG, "setupChild position:" + position + " h:" + h + " w:" + w);
    }

    final int childrenLeft = getChildLeft(position);

    if (needToMeasure) {
        final int childRight = childrenLeft + w;
        final int childBottom = childTop + h;
        onLayoutChild(child, position, flowDown, childrenLeft, childTop, childRight, childBottom);
    }
    else {
        onOffsetChild(child, position, flowDown, childrenLeft, childTop);
    }

}
 
源代码16 项目: UltimateAndroid   文件: ExtendableListView.java
/**
 * Add a view as a child and make sure it is measured (if necessary) and
 * positioned properly.
 *
 * @param child    The view to add
 * @param position The position of this child
 * @param y        The y position relative to which this view will be positioned
 * @param flowDown If true, align top edge to y. If false, align bottom
 *                 edge to y.
 * @param selected Is this position selected?
 * @param recycled Has this view been pulled from the recycle bin? If so it
 *                 does not need to be remeasured.
 */
private void setupChild(View child, int position, int y, boolean flowDown,
                        boolean selected, boolean recycled) {
    final boolean isSelected = false; // TODO : selected && shouldShowSelector();
    final boolean updateChildSelected = isSelected != child.isSelected();
    final int mode = mTouchMode;
    final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLLING &&
            mMotionPosition == position;
    final boolean updateChildPressed = isPressed != child.isPressed();
    final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

    int itemViewType = mAdapter.getItemViewType(position);

    LayoutParams layoutParams;
    if (itemViewType == ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
        layoutParams = generateWrapperLayoutParams(child);
    }
    else {
        layoutParams = generateChildLayoutParams(child);
    }

    layoutParams.viewType = itemViewType;
    layoutParams.position = position;

    if (recycled || (layoutParams.recycledHeaderFooter &&
            layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER)) {
        if (DBG) Log.d(TAG, "setupChild attachViewToParent position:" + position);
        attachViewToParent(child, flowDown ? -1 : 0, layoutParams);
    }
    else {
        if (DBG) Log.d(TAG, "setupChild addViewInLayout position:" + position);
        if (layoutParams.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
            layoutParams.recycledHeaderFooter = true;
        }
        addViewInLayout(child, flowDown ? -1 : 0, layoutParams, true);
    }

    if (updateChildSelected) {
        child.setSelected(isSelected);
    }

    if (updateChildPressed) {
        child.setPressed(isPressed);
    }

    if (needToMeasure) {
        if (DBG) Log.d(TAG, "setupChild onMeasureChild position:" + position);
        onMeasureChild(child, layoutParams);
    }
    else {
        if (DBG) Log.d(TAG, "setupChild cleanupLayoutState position:" + position);
        cleanupLayoutState(child);
    }

    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();
    final int childTop = flowDown ? y : y - h;

    if (DBG) {
        Log.d(TAG, "setupChild position:" + position + " h:" + h + " w:" + w);
    }

    final int childrenLeft = getChildLeft(position);

    if (needToMeasure) {
        final int childRight = childrenLeft + w;
        final int childBottom = childTop + h;
        onLayoutChild(child, position, flowDown, childrenLeft, childTop, childRight, childBottom);
    }
    else {
        onOffsetChild(child, position, flowDown, childrenLeft, childTop);
    }

}
 
@Override
public int getItemViewType(int position) {

    final int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
    final int adapterViewTypeStart = mAdapter == null ? 0 : mAdapter.getViewTypeCount() - 1;
    int type = AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER;
    if (mCachePlaceHoldView) {
        // Header
        if (position < numHeadersAndPlaceholders) {
            if (position == 0) {
                if (mCacheFirstHeaderView) {
                    type = adapterViewTypeStart + mHeaderViewInfos.size() + mFooterViewInfos.size() + 1 + 1;
                }
            }
            if (position % mNumColumns != 0) {
                type = adapterViewTypeStart + (position / mNumColumns + 1);
            }
        }
    }

    // Adapter
    final int adjPosition = position - numHeadersAndPlaceholders;
    int adapterCount = 0;
    if (mAdapter != null) {
        adapterCount = getAdapterAndPlaceHolderCount();
        if (adjPosition >= 0 && adjPosition < adapterCount) {
            if (adjPosition < mAdapter.getCount()) {
                type = mAdapter.getItemViewType(adjPosition);
            } else {
                if (mCachePlaceHoldView) {
                    type = adapterViewTypeStart + mHeaderViewInfos.size() + 1;
                }
            }
        }
    }

    if (mCachePlaceHoldView) {
        // Footer
        final int footerPosition = adjPosition - adapterCount;
        if (footerPosition >= 0 && footerPosition < getCount() && (footerPosition % mNumColumns) != 0) {
            type = adapterViewTypeStart + mHeaderViewInfos.size() + 1 + (footerPosition / mNumColumns + 1);
        }
    }

    return type;
}