Java Code Examples for android.widget.ListAdapter#getItemViewType()
The following examples show how to use
android.widget.ListAdapter#getItemViewType() .
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: PinnedSectionListView.java From Contacts with MIT License | 6 votes |
int findCurrentSectionPosition(int fromPosition) { ListAdapter adapter = getAdapter(); if (adapter instanceof SectionIndexer) { // try fast way by asking section indexer SectionIndexer indexer = (SectionIndexer) adapter; int sectionPosition = indexer.getSectionForPosition(fromPosition); int itemPosition = indexer.getPositionForSection(sectionPosition); int typeView = adapter.getItemViewType(itemPosition); if (isItemViewTypePinned(adapter, typeView)) { return itemPosition; } // else, no luck } // try slow way by looking through to the next section item above for (int position=fromPosition; position>=0; position--) { int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; // no candidate found }
Example 2
Source File: PinnedSectionListView.java From AndroidWeekly with Apache License 2.0 | 6 votes |
int findFirstVisibleSectionPosition(int firstVisibleItem, int visibleItemCount) { ListAdapter adapter = getAdapter(); int adapterDataCount = adapter.getCount(); if (getLastVisiblePosition() >= adapterDataCount) return -1; // dataset has changed, no candidate if (firstVisibleItem + visibleItemCount >= adapterDataCount) {//added to prevent index Outofbound (in case) visibleItemCount = adapterDataCount - firstVisibleItem; } for (int childIndex = 0; childIndex < visibleItemCount; childIndex++) { int position = firstVisibleItem + childIndex; int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; }
Example 3
Source File: PinnedSectionListView.java From Kernel-Tuner with GNU General Public License v3.0 | 6 votes |
int findCurrentSectionPosition(int fromPosition) { ListAdapter adapter = getAdapter(); if (adapter instanceof SectionIndexer) { // try fast way by asking section indexer SectionIndexer indexer = (SectionIndexer) adapter; int sectionPosition = indexer.getSectionForPosition(fromPosition); int itemPosition = indexer.getPositionForSection(sectionPosition); int typeView = adapter.getItemViewType(itemPosition); if (isItemViewTypePinned(adapter, typeView)) { return itemPosition; } // else, no luck } // try slow way by looking through to the next section item above for (int position=fromPosition; position>=0; position--) { int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; // no candidate found }
Example 4
Source File: PinnedSectionListView.java From Yahala-Messenger with MIT License | 6 votes |
int findCurrentSectionPosition(int fromPosition) { ListAdapter adapter = getAdapter(); if (adapter instanceof SectionIndexer) { // try fast way by asking section indexer SectionIndexer indexer = (SectionIndexer) adapter; int sectionPosition = indexer.getSectionForPosition(fromPosition); int itemPosition = indexer.getPositionForSection(sectionPosition); int typeView = adapter.getItemViewType(itemPosition); if (isItemViewTypePinned(adapter, typeView)) { return itemPosition; } // else, no luck } // try slow way by looking through to the next section item above for (int position = fromPosition; position >= 0; position--) { int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; // no candidate found }
Example 5
Source File: PinnedSectionListView.java From PullToRefresh-PinnedSection-ListView with MIT License | 6 votes |
int findCurrentSectionPosition(int fromPosition) { ListAdapter adapter = getAdapter(); if (adapter instanceof SectionIndexer) { // try fast way by asking section indexer SectionIndexer indexer = (SectionIndexer) adapter; int sectionPosition = indexer.getSectionForPosition(fromPosition); int itemPosition = indexer.getPositionForSection(sectionPosition); int typeView = adapter.getItemViewType(itemPosition); if (isItemViewTypePinned(adapter, typeView)) { return itemPosition; } // else, no luck } // try slow way by looking through to the next section item above for (int position=fromPosition; position>=0; position--) { int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; // no candidate found }
Example 6
Source File: MergeAdapter.java From mimicry with Apache License 2.0 | 6 votes |
/** * Get the type of {@link View} that will be created by {@link #getView(int, View, ViewGroup)} for the specified * item. * @param position Position of the item whose data we want */ @Override public int getItemViewType(int position) { int typeOffset = 0; int result = -1; for (ListAdapter piece : pieces) { int size = piece.getCount(); if (position < size) { result = typeOffset + piece.getItemViewType(position); break; } position -= size; typeOffset += piece.getViewTypeCount(); } return (result); }
Example 7
Source File: PinnedSectionListView.java From KUAS-AP-Material with MIT License | 6 votes |
int findFirstVisibleSectionPosition(int firstVisibleItem, int visibleItemCount) { ListAdapter adapter = getAdapter(); int adapterDataCount = adapter.getCount(); // dataset has changed, no candidate if (getLastVisiblePosition() >= adapterDataCount) { return -1; } //added to prevent index Outofbound (in case) if (firstVisibleItem + visibleItemCount >= adapterDataCount) { visibleItemCount = adapterDataCount - firstVisibleItem; } for (int childIndex = 0; childIndex < visibleItemCount; childIndex++) { int position = firstVisibleItem + childIndex; int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) { return position; } } return -1; }
Example 8
Source File: PinnedSectionListView.java From Contacts with MIT License | 5 votes |
int findFirstVisibleSectionPosition(int firstVisibleItem, int visibleItemCount) { ListAdapter adapter = getAdapter(); for (int childIndex = 0; childIndex < visibleItemCount; childIndex++) { int position = firstVisibleItem + childIndex; int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; }
Example 9
Source File: PinnedSectionListView.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
int findFirstVisibleSectionPosition(int firstVisibleItem, int visibleItemCount) { ListAdapter adapter = getAdapter(); for (int childIndex = 0; childIndex < visibleItemCount; childIndex++) { int position = firstVisibleItem + childIndex; int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; }
Example 10
Source File: Spinner.java From material with Apache License 2.0 | 5 votes |
public int getItemViewType(int position) { final ListAdapter adapter = mListAdapter; if (adapter != null) return adapter.getItemViewType(position); else return 0; }
Example 11
Source File: PinnedSectionListView.java From KUAS-AP-Material with MIT License | 5 votes |
int findCurrentSectionPosition(int fromPosition) { ListAdapter adapter = getAdapter(); // dataset has changed, no candidate if (fromPosition >= adapter.getCount()) { return -1; } if (adapter instanceof SectionIndexer) { // try fast way by asking section indexer SectionIndexer indexer = (SectionIndexer) adapter; int sectionPosition = indexer.getSectionForPosition(fromPosition); int itemPosition = indexer.getPositionForSection(sectionPosition); int typeView = adapter.getItemViewType(itemPosition); if (isItemViewTypePinned(adapter, typeView)) { return itemPosition; } // else, no luck } // try slow way by looking through to the next section item above for (int position = fromPosition; position >= 0; position--) { int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) { return position; } } // no candidate found return -1; }
Example 12
Source File: PinnedSectionListView.java From KUAS-AP-Material with MIT License | 5 votes |
int findCurrentSectionPosition(int fromPosition) { ListAdapter adapter = getAdapter(); // dataset has changed, no candidate if (fromPosition >= adapter.getCount()) { return -1; } if (adapter instanceof SectionIndexer) { // try fast way by asking section indexer SectionIndexer indexer = (SectionIndexer) adapter; int sectionPosition = indexer.getSectionForPosition(fromPosition); int itemPosition = indexer.getPositionForSection(sectionPosition); int typeView = adapter.getItemViewType(itemPosition); if (isItemViewTypePinned(adapter, typeView)) { return itemPosition; } // else, no luck } // try slow way by looking through to the next section item above for (int position = fromPosition; position >= 0; position--) { int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) { return position; } } // no candidate found return -1; }
Example 13
Source File: ListViewCompat.java From material with Apache License 2.0 | 4 votes |
/** * Measures the height of the given range of children (inclusive) and returns the height * with this ListView's padding and divider heights included. If maxHeight is provided, the * measuring will stop when the current height reaches maxHeight. * * @param widthMeasureSpec The width measure spec to be given to a child's * {@link View#measure(int, int)}. * @param startPosition The position of the first child to be shown. * @param endPosition The (inclusive) position of the last child to be * shown. Specify {@link #NO_POSITION} if the last child * should be the last available child from the adapter. * @param maxHeight The maximum height that will be returned (if all the * children don't fit in this value, this value will be * returned). * @param disallowPartialChildPosition In general, whether the returned height should only * contain entire children. This is more powerful--it is * the first inclusive position at which partial * children will not be allowed. Example: it looks nice * to have at least 3 completely visible children, and * in portrait this will most likely fit; but in * landscape there could be times when even 2 children * can not be completely shown, so a value of 2 * (remember, inclusive) would be good (assuming * startPosition is 0). * @return The height of this ListView with the given children. */ public int measureHeightOfChildrenCompat(int widthMeasureSpec, int startPosition, int endPosition, final int maxHeight, int disallowPartialChildPosition) { final int paddingTop = getListPaddingTop(); final int paddingBottom = getListPaddingBottom(); final int paddingLeft = getListPaddingLeft(); final int paddingRight = getListPaddingRight(); final int reportedDividerHeight = getDividerHeight(); final Drawable divider = getDivider(); final ListAdapter adapter = getAdapter(); if (adapter == null) { return paddingTop + paddingBottom; } // Include the padding of the list int returnedHeight = paddingTop + paddingBottom; final int dividerHeight = ((reportedDividerHeight > 0) && divider != null) ? reportedDividerHeight : 0; // The previous height value that was less than maxHeight and contained // no partial children int prevHeightWithoutPartialChild = 0; View child = null; int viewType = 0; int count = adapter.getCount(); for (int i = 0; i < count; i++) { int newType = adapter.getItemViewType(i); if (newType != viewType) { child = null; viewType = newType; } child = adapter.getView(i, child, this); // Compute child height spec int heightMeasureSpec; ViewGroup.LayoutParams childLp = child.getLayoutParams(); if (childLp == null) { childLp = generateDefaultLayoutParams(); child.setLayoutParams(childLp); } if (childLp.height > 0) { heightMeasureSpec = MeasureSpec.makeMeasureSpec(childLp.height, MeasureSpec.EXACTLY); } else { heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } child.measure(widthMeasureSpec, heightMeasureSpec); // Since this view was measured directly aginst the parent measure // spec, we must measure it again before reuse. child.forceLayout(); if (i > 0) { // Count the divider for all but one child returnedHeight += dividerHeight; } returnedHeight += child.getMeasuredHeight(); if (returnedHeight >= maxHeight) { // We went over, figure out which height to return. If returnedHeight > // maxHeight, then the i'th position did not fit completely. return (disallowPartialChildPosition >= 0) // Disallowing is enabled (> -1) && (i > disallowPartialChildPosition) // We've past the min pos && (prevHeightWithoutPartialChild > 0) // We have a prev height && (returnedHeight != maxHeight) // i'th child did not fit completely ? prevHeightWithoutPartialChild : maxHeight; } if ((disallowPartialChildPosition >= 0) && (i >= disallowPartialChildPosition)) { prevHeightWithoutPartialChild = returnedHeight; } } // At this point, we went through the range of children, and they each // completely fit, so return the returnedHeight return returnedHeight; }
Example 14
Source File: DragSortListView.java From chromadoze with GNU General Public License v3.0 | 4 votes |
private int getChildHeight(int position) { if (position == mSrcPos) { return 0; } View v = getChildAt(position - getFirstVisiblePosition()); if (v != null) { // item is onscreen, therefore child height is valid, // hence the "true" return getChildHeight(position, v, false); } else { // item is offscreen // first check cache for child height at this position int childHeight = mChildHeightCache.get(position); if (childHeight != -1) { // Log.d("mobeta", "found child height in cache!"); return childHeight; } final ListAdapter adapter = getAdapter(); int type = adapter.getItemViewType(position); // There might be a better place for checking for the following final int typeCount = adapter.getViewTypeCount(); if (typeCount != mSampleViewTypes.length) { mSampleViewTypes = new View[typeCount]; } if (type >= 0) { if (mSampleViewTypes[type] == null) { v = adapter.getView(position, null, this); mSampleViewTypes[type] = v; } else { v = adapter.getView(position, mSampleViewTypes[type], this); } } else { // type is HEADER_OR_FOOTER or IGNORE v = adapter.getView(position, null, this); } // current child height is invalid, hence "true" below childHeight = getChildHeight(position, v, true); // cache it because this could have been expensive mChildHeightCache.add(position, childHeight); return childHeight; } }
Example 15
Source File: DragSortListView.java From Overchan-Android with GNU General Public License v3.0 | 4 votes |
private int getChildHeight(int position) { if (position == mSrcPos) { return 0; } View v = getChildAt(position - getFirstVisiblePosition()); if (v != null) { // item is onscreen, therefore child height is valid, // hence the "true" return getChildHeight(position, v, false); } else { // item is offscreen // first check cache for child height at this position int childHeight = mChildHeightCache.get(position); if (childHeight != -1) { // Log.d("mobeta", "found child height in cache!"); return childHeight; } final ListAdapter adapter = getAdapter(); int type = adapter.getItemViewType(position); // There might be a better place for checking for the following final int typeCount = adapter.getViewTypeCount(); if (typeCount != mSampleViewTypes.length) { mSampleViewTypes = new View[typeCount]; } if (type >= 0) { if (mSampleViewTypes[type] == null) { v = adapter.getView(position, null, this); mSampleViewTypes[type] = v; } else { v = adapter.getView(position, mSampleViewTypes[type], this); } } else { // type is HEADER_OR_FOOTER or IGNORE v = adapter.getView(position, null, this); } // current child height is invalid, hence "true" below childHeight = getChildHeight(position, v, true); // cache it because this could have been expensive mChildHeightCache.add(position, childHeight); return childHeight; } }
Example 16
Source File: DragSortListView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
private int getChildHeight(int position) { if (position == mSrcPos) { return 0; } View v = getChildAt(position - getFirstVisiblePosition()); if (v != null) { // item is onscreen, therefore child height is valid, // hence the "true" return getChildHeight(position, v, false); } else { // item is offscreen // first check cache for child height at this position int childHeight = mChildHeightCache.get(position); if (childHeight != -1) { // Log.d("mobeta", "found child height in cache!"); return childHeight; } final ListAdapter adapter = getAdapter(); int type = adapter.getItemViewType(position); // There might be a better place for checking for the following final int typeCount = adapter.getViewTypeCount(); if (typeCount != mSampleViewTypes.length) { mSampleViewTypes = new View[typeCount]; } if (type >= 0) { if (mSampleViewTypes[type] == null) { v = adapter.getView(position, null, this); mSampleViewTypes[type] = v; } else { v = adapter.getView(position, mSampleViewTypes[type], this); } } else { // type is HEADER_OR_FOOTER or IGNORE v = adapter.getView(position, null, this); } // current child height is invalid, hence "true" below childHeight = getChildHeight(position, v, true); // cache it because this could have been expensive mChildHeightCache.add(position, childHeight); return childHeight; } }
Example 17
Source File: DragSortListView.java From google-authenticator-android with Apache License 2.0 | 4 votes |
private int getChildHeight(int position) { if (position == mSrcPos) { return 0; } View v = getChildAt(position - getFirstVisiblePosition()); if (v != null) { // item is onscreen, therefore child height is valid, // hence the "true" return getChildHeight(position, v, false); } else { // item is offscreen // first check cache for child height at this position int childHeight = mChildHeightCache.get(position); if (childHeight != -1) { // Log.d("mobeta", "found child height in cache!"); return childHeight; } final ListAdapter adapter = getAdapter(); int type = adapter.getItemViewType(position); // There might be a better place for checking for the following final int typeCount = adapter.getViewTypeCount(); if (typeCount != mSampleViewTypes.length) { mSampleViewTypes = new View[typeCount]; } if (type >= 0) { if (mSampleViewTypes[type] == null) { v = adapter.getView(position, null, this); mSampleViewTypes[type] = v; } else { v = adapter.getView(position, mSampleViewTypes[type], this); } } else { // type is HEADER_OR_FOOTER or IGNORE v = adapter.getView(position, null, this); } // current child height is invalid, hence "true" below childHeight = getChildHeight(position, v, true); // cache it because this could have been expensive mChildHeightCache.add(position, childHeight); return childHeight; } }
Example 18
Source File: DragSortListView.java From Field-Book with GNU General Public License v2.0 | 4 votes |
private int getChildHeight(int position) { if (position == mSrcPos) { return 0; } View v = getChildAt(position - getFirstVisiblePosition()); if (v != null) { // item is onscreen, therefore child height is valid, // hence the "true" return getChildHeight(position, v, false); } else { // item is offscreen // first check cache for child height at this position int childHeight = mChildHeightCache.get(position); if (childHeight != -1) { return childHeight; } final ListAdapter adapter = getAdapter(); int type = adapter.getItemViewType(position); // There might be a better place for checking for the following final int typeCount = adapter.getViewTypeCount(); if (typeCount != mSampleViewTypes.length) { mSampleViewTypes = new View[typeCount]; } if (type >= 0) { if (mSampleViewTypes[type] == null) { v = adapter.getView(position, null, this); mSampleViewTypes[type] = v; } else { v = adapter.getView(position, mSampleViewTypes[type], this); } } else { // type is HEADER_OR_FOOTER or IGNORE v = adapter.getView(position, null, this); } // current child height is invalid, hence "true" below childHeight = getChildHeight(position, v, true); // cache it because this could have been expensive mChildHeightCache.add(position, childHeight); return childHeight; } }
Example 19
Source File: DragSortListView.java From UltimateAndroid with Apache License 2.0 | 4 votes |
private int getChildHeight(int position) { if (position == mSrcPos) { return 0; } View v = getChildAt(position - getFirstVisiblePosition()); if (v != null) { // item is onscreen, therefore child height is valid, // hence the "true" return getChildHeight(position, v, false); } else { // item is offscreen // first check cache for child height at this position int childHeight = mChildHeightCache.get(position); if (childHeight != -1) { // Log.d("mobeta", "found child height in cache!"); return childHeight; } final ListAdapter adapter = getAdapter(); int type = adapter.getItemViewType(position); // There might be a better place for checking for the following final int typeCount = adapter.getViewTypeCount(); if (typeCount != mSampleViewTypes.length) { mSampleViewTypes = new View[typeCount]; } if (type >= 0) { if (mSampleViewTypes[type] == null) { v = adapter.getView(position, null, this); mSampleViewTypes[type] = v; } else { v = adapter.getView(position, mSampleViewTypes[type], this); } } else { // type is HEADER_OR_FOOTER or IGNORE v = adapter.getView(position, null, this); } // current child height is invalid, hence "true" below childHeight = getChildHeight(position, v, true); // cache it because this could have been expensive mChildHeightCache.add(position, childHeight); return childHeight; } }
Example 20
Source File: DragSortListView.java From android-kernel-tweaker with GNU General Public License v3.0 | 4 votes |
private int getChildHeight(int position) { if (position == mSrcPos) { return 0; } View v = getChildAt(position - getFirstVisiblePosition()); if (v != null) { // item is onscreen, therefore child height is valid, // hence the "true" return getChildHeight(position, v, false); } else { // item is offscreen // first check cache for child height at this position int childHeight = mChildHeightCache.get(position); if (childHeight != -1) { // Log.d("mobeta", "found child height in cache!"); return childHeight; } final ListAdapter adapter = getAdapter(); int type = adapter.getItemViewType(position); // There might be a better place for checking for the following final int typeCount = adapter.getViewTypeCount(); if (typeCount != mSampleViewTypes.length) { mSampleViewTypes = new View[typeCount]; } if (type >= 0) { if (mSampleViewTypes[type] == null) { v = adapter.getView(position, null, this); mSampleViewTypes[type] = v; } else { v = adapter.getView(position, mSampleViewTypes[type], this); } } else { // type is HEADER_OR_FOOTER or IGNORE v = adapter.getView(position, null, this); } // current child height is invalid, hence "true" below childHeight = getChildHeight(position, v, true); // cache it because this could have been expensive mChildHeightCache.add(position, childHeight); return childHeight; } }