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 .
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
Source File: HeaderGridView.java From AcDisplay with GNU General Public License v2.0 | 6 votes |
@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
Source File: HeaderGridView.java From HeadsUp with GNU General Public License v2.0 | 6 votes |
@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
Source File: HeaderGridView.java From AnimatedGridView with Apache License 2.0 | 6 votes |
@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 4
Source File: HeaderGridView.java From BigApp_WordPress_Android with Apache License 2.0 | 6 votes |
@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 5
Source File: HeaderFooterGridView.java From android-HeaderFooterGridView with Apache License 2.0 | 6 votes |
@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 6
Source File: HeaderGridView.java From MutiPhotoChoser with Mozilla Public License 2.0 | 6 votes |
@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 7
Source File: HeaderGridView.java From HeartbeatFixerForGCM with Apache License 2.0 | 6 votes |
@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
Source File: HeaderFooterViewListAdapter.java From ProjectX with Apache License 2.0 | 5 votes |
@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 9
Source File: RefreshRecyclerViewAdapter.java From RecyclerViewManager with MIT License | 5 votes |
@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
Source File: HeaderViewListAdapter.java From Klyph with MIT License | 5 votes |
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 11
Source File: HeaderViewListAdapter.java From UltimateAndroid with Apache License 2.0 | 5 votes |
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
Source File: FooterViewGridAdapter.java From PagingGridView with Apache License 2.0 | 5 votes |
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 13
Source File: HeaderViewListAdapter.java From PullToRefreshLibrary with Apache License 2.0 | 5 votes |
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 14
Source File: ExtendableListView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
/** * 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
Source File: ExtendableListView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
/** * 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
Source File: ObservableGridView.java From Android-ObservableScrollView with Apache License 2.0 | 4 votes |
@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; }
Example 17
Source File: ExtendableListView.java From PullToRefreshLibrary with Apache License 2.0 | 4 votes |
/** * 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); } }