Java Code Examples for android.widget.AbsListView#CHOICE_MODE_MULTIPLE

The following examples show how to use android.widget.AbsListView#CHOICE_MODE_MULTIPLE . 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: BaseConfigureChildFragment.java    From Storm with Apache License 2.0 6 votes vote down vote up
protected void processSelectedStates(ListView listView, ConfigureAdapterItem[] items) {
    final int choiceMode = listView.getChoiceMode();
    if (choiceMode == AbsListView.CHOICE_MODE_MULTIPLE) {
        final SparseBooleanArray array = listView.getCheckedItemPositions();
        int key;
        for (int i = 0; i < array.size(); i++) {
            key = array.keyAt(i);
            items[key].setChecked(array.valueAt(i));
        }
    } else if (choiceMode == AbsListView.CHOICE_MODE_SINGLE) {
        final int position = listView.getCheckedItemPosition();
        for (int i = 0; i < items.length; i++) {
            items[i].setChecked(i == position);
        }
    }
}
 
Example 2
Source File: LovelyChoiceDialog.java    From LovelyDialog with Apache License 2.0 4 votes vote down vote up
private boolean isMultiChoiceList() {
    return choicesList.getChoiceMode() == AbsListView.CHOICE_MODE_MULTIPLE;
}
 
Example 3
Source File: TrackSelectionAdapterWrapper.java    From ticdesign with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the checked state of the specified position. The is only valid if
 * the choice mode has been set to {@link AbsListView#CHOICE_MODE_SINGLE} or
 * {@link AbsListView#CHOICE_MODE_MULTIPLE}.
 *
 * @param position The item whose checked state is to be checked
 * @param value The new checked state for the item
 */
public void setItemChecked(int position, boolean value) {
    if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) {
        return;
    }

    // Start selection mode if needed. We don't need to if we're unchecking something.
    if (value && mAttachedRecyclerView != null) {
        startSelectionModeIfNeeded(mAttachedRecyclerView);
    }

    if (mChoiceMode == AbsListView.CHOICE_MODE_MULTIPLE || mChoiceMode == AbsListView.CHOICE_MODE_MULTIPLE_MODAL) {
        boolean oldValue = mCheckStates.get(position);
        mCheckStates.put(position, value);
        if (mCheckedIdStates != null && hasStableIds()) {
            if (value) {
                mCheckedIdStates.put(getItemId(position), position);
            } else {
                mCheckedIdStates.delete(getItemId(position));
            }
        }
        if (oldValue != value) {
            if (value) {
                mCheckedItemCount++;
            } else {
                mCheckedItemCount--;
            }
            updateCheckStateIfPossible(null, position);
            fireOnSelected(null);
        }
        if (mChoiceActionMode != null) {
            final long id = getItemId(position);
            mMultiChoiceModeCallback.onItemCheckedStateChanged(mChoiceActionMode,
                    position, id, value);
        }
    } else {
        int checkedPosition = getCheckedItemPosition();
        boolean updateIds = mCheckedIdStates != null && 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(getItemId(position), position);
            }
            mCheckedItemCount = 1;
        } else if (mCheckStates.size() == 0 || !mCheckStates.valueAt(0)) {
            mCheckedItemCount = 0;
        }
        if (checkedPosition != position) {
            if (checkedPosition != AbsListView.INVALID_POSITION)
                updateCheckStateIfPossible(null, checkedPosition);
            updateCheckStateIfPossible(null, position);
            fireOnSelected(null);
        }
    }
}
 
Example 4
Source File: ConfigureOpType.java    From Storm with Apache License 2.0 4 votes vote down vote up
@Override
protected int getListViewChoiceMode() {
    return AbsListView.CHOICE_MODE_MULTIPLE;
}
 
Example 5
Source File: ConfigureRounds.java    From Storm with Apache License 2.0 4 votes vote down vote up
@Override
protected int getListViewChoiceMode() {
    return AbsListView.CHOICE_MODE_MULTIPLE;
}
 
Example 6
Source File: ConfigureORMs.java    From Storm with Apache License 2.0 4 votes vote down vote up
@Override
protected int getListViewChoiceMode() {
    return AbsListView.CHOICE_MODE_MULTIPLE;
}