Example usage for android.widget ListAdapter hasStableIds

List of usage examples for android.widget ListAdapter hasStableIds

Introduction

In this page you can find the example usage for android.widget ListAdapter hasStableIds.

Prototype

boolean hasStableIds();

Source Link

Document

Indicates whether the item ids are stable across changes to the underlying data.

Usage

From source file:com.artifex.mupdflib.TwoWayView.java

@Override
public void setAdapter(ListAdapter adapter) {
    if (mAdapter != null && mDataSetObserver != null) {
        mAdapter.unregisterDataSetObserver(mDataSetObserver);
    }/*from   ww w .java  2 s  . c  om*/

    resetState();
    mRecycler.clear();

    mAdapter = adapter;
    mDataChanged = true;

    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    if (mCheckStates != null) {
        mCheckStates.clear();
    }

    if (mCheckedIdStates != null) {
        mCheckedIdStates.clear();
    }

    if (mAdapter != null) {
        mOldItemCount = mItemCount;
        mItemCount = adapter.getCount();

        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);

        mRecycler.setViewTypeCount(adapter.getViewTypeCount());

        mHasStableIds = adapter.hasStableIds();
        mAreAllItemsSelectable = adapter.areAllItemsEnabled();

        if (mChoiceMode != ChoiceMode.NONE && mHasStableIds && mCheckedIdStates == null) {
            mCheckedIdStates = new LongSparseArray<Integer>();
        }

        final int position = lookForSelectablePosition(0);
        setSelectedPositionInt(position);
        setNextSelectedPositionInt(position);

        if (mItemCount == 0) {
            checkSelectionChanged();
        }
    } else {
        mItemCount = 0;
        mHasStableIds = false;
        mAreAllItemsSelectable = true;

        checkSelectionChanged();
    }

    checkFocus();
    requestLayout();
}