PreferenceGroupAdapter.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:AndroidPreferenceActivity 作者:
/**
 * Returns a pair, which contains the item, which corresponds to the given position, as well
 * as the item's position in the encapsulated adapter, if the item is not a divider.
 *
 * @param position
 *         The position of the item, which should be returned, as an {@link Integer} value
 * @return A pair, which contains the item, which corresponds to the given position, as well as
 * the item's position in the encapsulated adapter, if the item is not a divider, as an instance
 * of the class Pair. The pair may not be null
 */
@NonNull
public final Pair<Object, Integer> getItemInternal(final int position) {
    ensureAtLeast(position, 0, null, IndexOutOfBoundsException.class);
    Object item = null;
    int offset = 0;
    int i = 0;

    while (i <= position) {
        item = encapsulatedAdapter.getItem(i - offset);

        if (i > 0 && item instanceof PreferenceCategory) {
            if (i == position) {
                return Pair.create(DIVIDER, -1);
            } else {
                offset++;
                i++;
            }
        }

        i++;
    }

    ensureNotNull(item, null, IndexOutOfBoundsException.class);
    return Pair.create(item, i - 1 - offset);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号