Java Code Examples for android.widget.AdapterView#ITEM_VIEW_TYPE_HEADER_OR_FOOTER

The following examples show how to use android.widget.AdapterView#ITEM_VIEW_TYPE_HEADER_OR_FOOTER . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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;
}
 
Example 2
@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;
}
 
Example 3
@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;
}
 
Example 4
@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;
}
 
Example 5
@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;
}
 
Example 6
Source Project: AnimatedGridView   File: HeaderGridView.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 7
@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;
}
 
Example 8
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;
}
 
Example 9
@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;
    }
}
 
Example 10
@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;
}
 
Example 11
Source Project: Klyph   File: HeaderViewListAdapter.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example 12
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;
}
 
Example 13
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;
}
 
Example 14
/**
 * 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);
	}

}
 
Example 15
/**
 * 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);
    }

}
 
Example 16
/**
 * 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);
    }

}
 
Example 17
@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;
}