Code example for SparseBooleanArray

Methods: clear, get, put

0
        } else { 
            boolean updateIds = mCheckedIdStates != null && getAdapter().hasStableIds();
            // Clear all values if we're checking something, or unchecking the currently 
            // selected item 
            if (value || isItemChecked(position)) {
                mCheckStates.clear();
                if (updateIds) {
                    mCheckedIdStates.clear();
                } 
            } 
            // this may end up selecting the value we just cleared but this way 
            // we ensure length of mCheckStates is 1, a fact getCheckedItemPosition relies on 
            if (value) {
                mCheckStates.put(position, true);
                if (updateIds) {
                    mCheckedIdStates.put(getAdapter().getItemId(position), Boolean.TRUE);
                } 
            } 
        } 
         
        // Do not generate a data change while we are in the layout phase 
        //if (!mInLayout && !mBlockLayoutRequests) { 
        //mDataChanged = true; 
        //rememberSyncState(); 
        //requestLayout(); 
        //} 
        invalidateViews();
    } 
     
    @SuppressLint("NewApi") 
    @Override 
    public boolean isItemChecked(int position) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            return super.isItemChecked(position);
        } 
         
        if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
            return mCheckStates.get(position);
        } 
         
        return false; 
    }