Java Code Examples for android.widget.ListAdapter#getViewTypeCount()
The following examples show how to use
android.widget.ListAdapter#getViewTypeCount() .
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: MergeAdapter.java From SimpleExplorer with GNU General Public License v3.0 | 6 votes |
/** * Get the type of View that will be created by getView() 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 2
Source File: PinnedSectionListView.java From Kernel-Tuner with GNU General Public License v3.0 | 6 votes |
@Override public void setAdapter(ListAdapter adapter) { // assert adapter in debug mode if (BuildConfig.DEBUG && adapter != null) { if (!(adapter instanceof PinnedSectionListAdapter)) throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?"); if (adapter.getViewTypeCount() < 2) throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?"); } // unregister observer at old adapter and register on new one ListAdapter oldAdapter = getAdapter(); if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver); if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver); // destroy pinned shadow, if new adapter is not same as old one if (oldAdapter != adapter) destroyPinnedShadow(); super.setAdapter(adapter); }
Example 3
Source File: MergeAdapter.java From Shield with MIT License | 6 votes |
/** * Get the type of View that will be created by getView() 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 4
Source File: PinnedSectionListView.java From AndroidWeekly with Apache License 2.0 | 6 votes |
@Override public void setAdapter(ListAdapter adapter) { // assert adapter in debug mode if (BuildConfig.DEBUG && adapter != null) { if (!(adapter instanceof PinnedSectionListAdapter)) throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?"); if (adapter.getViewTypeCount() < 2) throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?"); } // unregister observer at old adapter and register on new one ListAdapter oldAdapter = getAdapter(); if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver); if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver); // destroy pinned shadow, if new adapter is not same as old one if (oldAdapter != adapter) destroyPinnedShadow(); super.setAdapter(adapter); }
Example 5
Source File: PinnedSectionListView.java From Yahala-Messenger with MIT License | 6 votes |
@Override public void setAdapter(ListAdapter adapter) { // assert adapter in debug mode if (BuildConfig.DEBUG && adapter != null) { if (!(adapter instanceof PinnedSectionListAdapter)) throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?"); if (adapter.getViewTypeCount() < 2) throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?"); } // unregister observer at old adapter and register on new one ListAdapter oldAdapter = getAdapter(); if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver); if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver); // destroy pinned shadow, if new adapter is not same as old one if (oldAdapter != adapter) destroyPinnedShadow(); super.setAdapter(adapter); }
Example 6
Source File: PinnedSectionListView.java From PullToRefresh-PinnedSection-ListView with MIT License | 6 votes |
@Override public void setAdapter(ListAdapter adapter) { // assert adapter in debug mode if (BuildConfig.DEBUG && adapter != null) { if (!(adapter instanceof PinnedSectionListAdapter)) throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?"); if (adapter.getViewTypeCount() < 2) throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?"); } // unregister observer at old adapter and register on new one ListAdapter oldAdapter = getAdapter(); if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver); if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver); // destroy pinned shadow, if new adapter is not same as old one if (oldAdapter != adapter) destroyPinnedShadow(); super.setAdapter(adapter); }
Example 7
Source File: PinnedSectionListView.java From Contacts with MIT License | 6 votes |
@Override public void setAdapter(ListAdapter adapter) { // assert adapter in debug mode if (BuildConfig.DEBUG && adapter != null) { if (!(adapter instanceof PinnedSectionListAdapter)) throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?"); if (adapter.getViewTypeCount() < 2) throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?"); } // unregister observer at old adapter and register on new one ListAdapter oldAdapter = getAdapter(); if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver); if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver); // destroy pinned shadow, if new adapter is not same as old one if (oldAdapter != adapter) destroyPinnedShadow(); super.setAdapter(adapter); }
Example 8
Source File: PinnedSectionListView.java From android-open-project-demo with Apache License 2.0 | 6 votes |
@Override public void setAdapter(ListAdapter adapter) { // assert adapter in debug mode if (BuildConfig.DEBUG && adapter != null) { if (!(adapter instanceof PinnedSectionListAdapter)) throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?"); if (adapter.getViewTypeCount() < 2) throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?"); } // unregister observer at old adapter and register on new one ListAdapter oldAdapter = getAdapter(); if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver); if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver); // destroy pinned shadow, if new adapter is not same as old one if (oldAdapter != adapter) destroyPinnedShadow(); super.setAdapter(adapter); }
Example 9
Source File: Spinner.java From MDPreference with Apache License 2.0 | 5 votes |
public int getViewTypeCount() { final ListAdapter adapter = mListAdapter; if (adapter != null) return adapter.getViewTypeCount(); else return 1; }
Example 10
Source File: PinnedSectionListView.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
@Override public void setAdapter(ListAdapter adapter) { // assert adapter in debug mode if (adapter != null) { if (!(adapter instanceof PinnedSectionListAdapter)) throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?"); if (adapter.getViewTypeCount() < 2) throw new IllegalArgumentException("Does your adapter handle at least two types" + " of views in getViewTypeCount() method: items and sections?"); } // unregister observer at old adapter and register on new one ListAdapter oldAdapter = getAdapter(); if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver); if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver); // destroy pinned shadow, if new adapter is not same as old one if (oldAdapter != adapter) destroyPinnedShadow(); Log.e("APP", "mLvFooterLoadingFrame:" + mLvFooterLoadingFrame + " mAddedLvFooter:" + mAddedLvFooter); if (null != mLvFooterLoadingFrame && !mAddedLvFooter) { addFooterView(mLvFooterLoadingFrame, null, false); mAddedLvFooter = true; } super.setAdapter(adapter); }
Example 11
Source File: MergeAdapter.java From mimicry with Apache License 2.0 | 5 votes |
/** * Returns the number of types of {@link View}s that will be created by {@link #getView(int, View, ViewGroup)}. */ @Override public int getViewTypeCount() { int total = 0; for (ListAdapter piece : pieces) { total += piece.getViewTypeCount(); } return (Math.max(total, 1)); // needed for setListAdapter() before // content add' }
Example 12
Source File: MergeAdapter.java From SimpleExplorer with GNU General Public License v3.0 | 5 votes |
/** * Returns the number of types of Views that will be created by getView(). */ @Override public int getViewTypeCount() { int total = 0; for (ListAdapter piece : pieces) { total += piece.getViewTypeCount(); } return Math.max(total, 1); // needed for setListAdapter() before // content add' }
Example 13
Source File: Spinner.java From material with Apache License 2.0 | 5 votes |
public int getViewTypeCount() { final ListAdapter adapter = mListAdapter; if (adapter != null) return adapter.getViewTypeCount(); else return 1; }
Example 14
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 15
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 16
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 17
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; } }
Example 18
Source File: DragSortListView.java From biermacht 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 19
Source File: DragSortListView.java From mobile-manager-tool with MIT License | 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 onpc 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; } }