android.widget.ListAdapter#getViewTypeCount ( )源码实例Demo

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

源代码1 项目: Kernel-Tuner   文件: PinnedSectionListView.java
@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);
}
 
源代码2 项目: Shield   文件: MergeAdapter.java
/**
 * 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);
}
 
源代码3 项目: AndroidWeekly   文件: PinnedSectionListView.java
@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);
}
 
源代码4 项目: Yahala-Messenger   文件: PinnedSectionListView.java
@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);
}
 
源代码5 项目: Contacts   文件: PinnedSectionListView.java
@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);
}
 
@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);
}
 
@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);
}
 
源代码8 项目: SimpleExplorer   文件: MergeAdapter.java
/**
 * 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;
}
 
源代码9 项目: MDPreference   文件: Spinner.java
public int getViewTypeCount() {
	final ListAdapter adapter = mListAdapter;
    if (adapter != null)
        return adapter.getViewTypeCount();
    else
        return 1;
}
 
@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);
}
 
源代码11 项目: material   文件: Spinner.java
public int getViewTypeCount() {
	final ListAdapter adapter = mListAdapter;
    if (adapter != null)
        return adapter.getViewTypeCount();
    else
        return 1;
}
 
源代码12 项目: SimpleExplorer   文件: MergeAdapter.java
/**
 * 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'
}
 
源代码13 项目: mimicry   文件: MergeAdapter.java
/**
 * 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'
}
 
源代码14 项目: android-kernel-tweaker   文件: DragSortListView.java
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;
    }
}
 
源代码15 项目: onpc   文件: DragSortListView.java
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;
    }
}
 
源代码16 项目: mobile-manager-tool   文件: DragSortListView.java
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;
    }
}
 
源代码17 项目: biermacht   文件: DragSortListView.java
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;
  }
}
 
源代码18 项目: Overchan-Android   文件: DragSortListView.java
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;
    }
}
 
源代码19 项目: chromadoze   文件: DragSortListView.java
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;
    }
}
 
源代码20 项目: Field-Book   文件: DragSortListView.java
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;
    }
}