Java Code Examples for android.widget.listview#CHOICE_MODE_NONE

The following examples show how to use android.widget.listview#CHOICE_MODE_NONE . 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: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setAdapter( ListAdapter adapter ) {
	if ( adapter != null ) {
		mAdapterHasStableIds = mAdapter.hasStableIds();
		if ( mChoiceMode != ListView.CHOICE_MODE_NONE && mAdapterHasStableIds &&
				mCheckedIdStates == null ) {
			mCheckedIdStates = new LongSparseArray<Integer>();
		}
	}

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

	if ( mCheckedIdStates != null ) {
		mCheckedIdStates.clear();
	}
}
 
Example 2
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE} and the adapter has stable IDs. ({@link ListAdapter#hasStableIds()} == {@code true})
 * 
 * @return A new array which contains the id of each checked item in the list.
 */
public long[] getCheckedItemIds() {
	if ( mChoiceMode == ListView.CHOICE_MODE_NONE || mCheckedIdStates == null || mAdapter == null ) {
		return new long[0];
	}

	final LongSparseArray<Integer> idStates = mCheckedIdStates;
	final int count = idStates.size();
	final long[] ids = new long[count];

	for ( int i = 0; i < count; i++ ) {
		ids[i] = idStates.keyAt( i );
	}

	return ids;
}
 
Example 3
Source File: MainActivity.java    From android-tutorials-custom-selectable-listview with Apache License 2.0 6 votes vote down vote up
/**
 * Change the list selection mode
 */
private void toggleChoiceMode() {
	clearSelection();

	final int currentMode = listView.getChoiceMode();
	switch (currentMode) {
		case ListView.CHOICE_MODE_NONE:
			listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
			Toast.makeText(this, "List choice mode: SINGLE", Toast.LENGTH_SHORT).show();
			break;
		case ListView.CHOICE_MODE_SINGLE:
			listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
			Toast.makeText(this, "List choice mode: MULTIPLE", Toast.LENGTH_SHORT).show();
			break;
		case ListView.CHOICE_MODE_MULTIPLE:
			listView.setChoiceMode(ListView.CHOICE_MODE_NONE);
			Toast.makeText(this, "List choice mode: NONE", Toast.LENGTH_SHORT).show();
			break;
	}
}
 
Example 4
Source File: IcsListPopupWindow.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the selected position of the list.
 * Only valid when {@link #isShowing()} == {@code true}.
 *
 * @param position List position to set as selected.
 */
public void setSelection(int position) {
    DropDownListView list = mDropDownList;
    if (isShowing() && list != null) {
        list.mListSelectionHidden = false;
        list.setSelection(position);
        if (list.getChoiceMode() != ListView.CHOICE_MODE_NONE) {
            list.setItemChecked(position, true);
        }
    }
}
 
Example 5
Source File: HListView.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE}.
 * 
 * @return A new array which contains the id of each checked item in the list.
 * 
 * @deprecated Use {@link #getCheckedItemIds()} instead.
 */
@Deprecated
public long[] getCheckItemIds() {
	// Use new behavior that correctly handles stable ID mapping.
	if ( mAdapter != null && mAdapter.hasStableIds() ) {
		return getCheckedItemIds();
	}

	// Old behavior was buggy, but would sort of work for adapters without stable IDs.
	// Fall back to it to support legacy apps.
	if ( mChoiceMode != ListView.CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null ) {
		final SparseBooleanArray states = mCheckStates;
		final int count = states.size();
		final long[] ids = new long[count];
		final ListAdapter adapter = mAdapter;

		int checkedCount = 0;
		for ( int i = 0; i < count; i++ ) {
			if ( states.valueAt( i ) ) {
				ids[checkedCount++] = adapter.getItemId( states.keyAt( i ) );
			}
		}

		// Trim array if needed. mCheckStates may contain false values
		// resulting in checkedCount being smaller than count.
		if ( checkedCount == count ) {
			return ids;
		} else {
			final long[] result = new long[checkedCount];
			System.arraycopy( ids, 0, result, 0, checkedCount );

			return result;
		}
	}
	return new long[0];
}
 
Example 6
Source File: IcsListPopupWindow.java    From zen4android with MIT License 5 votes vote down vote up
/**
 * Set the selected position of the list.
 * Only valid when {@link #isShowing()} == {@code true}.
 *
 * @param position List position to set as selected.
 */
public void setSelection(int position) {
    DropDownListView list = mDropDownList;
    if (isShowing() && list != null) {
        list.mListSelectionHidden = false;
        list.setSelection(position);
        if (list.getChoiceMode() != ListView.CHOICE_MODE_NONE) {
            list.setItemChecked(position, true);
        }
    }
}
 
Example 7
Source File: IcsListPopupWindow.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
/**
 * Set the selected position of the list.
 * Only valid when {@link #isShowing()} == {@code true}.
 *
 * @param position List position to set as selected.
 */
public void setSelection(int position) {
    DropDownListView list = mDropDownList;
    if (isShowing() && list != null) {
        list.mListSelectionHidden = false;
        list.setSelection(position);
        if (list.getChoiceMode() != ListView.CHOICE_MODE_NONE) {
            list.setItemChecked(position, true);
        }
    }
}
 
Example 8
Source File: IcsListPopupWindow.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
/**
 * Set the selected position of the list.
 * Only valid when {@link #isShowing()} == {@code true}.
 *
 * @param position List position to set as selected.
 */
public void setSelection(int position) {
    DropDownListView list = mDropDownList;
    if (isShowing() && list != null) {
        list.mListSelectionHidden = false;
        list.setSelection(position);
        if (list.getChoiceMode() != ListView.CHOICE_MODE_NONE) {
            list.setItemChecked(position, true);
        }
    }
}
 
Example 9
Source File: RipperSimpleType.java    From AndroidRipper with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Detect SimpleType of a Widget
 * 
 * @param v Widget
 * @return
 */
public static String getSimpleType(View v, String type, boolean alreadyCalled)
{
	if (type.endsWith("null")) return NULL;
	if (type.endsWith("RadioButton")) return RADIO;
	if (type.endsWith("RadioGroup")) return RADIO_GROUP;
	if (type.endsWith("CheckBox") || type.endsWith("CheckedTextView")) return CHECKBOX;
	if (type.endsWith("ToggleButton")) return TOGGLE_BUTTON;
	if (type.endsWith("MenuDropDownListView") || type.endsWith("IconMenuView") || type.endsWith("ActionMenuView")) return MENU_VIEW;
	if (type.endsWith("ListMenuItemView") || type.endsWith("IconMenuItemView") || type.endsWith("ActionMenuItemView")) return MENU_ITEM;
	if (type.endsWith("DatePicker")) return DATE_PICKER;
	if (type.endsWith("TimePicker")) return TIME_PICKER;
	if (type.endsWith("DialogTitle")) return DIALOG_VIEW;
	if (type.endsWith("Button")) return BUTTON;
	if (type.endsWith("EditText")) return EDIT_TEXT;
	if (type.endsWith("SearchAutoComplete")) return SEARCH_BAR;
	if (type.endsWith("Spinner")) {
		Spinner s = (Spinner)v;
		if (s.getCount() == 0) return EMPTY_SPINNER;
		return SPINNER;
	}
	if (type.endsWith("SeekBar")) return SEEK_BAR;
	if (v instanceof RatingBar && (!((RatingBar)v).isIndicator())) return RATING_BAR;
	if (type.endsWith("TabHost")) return TAB_HOST;
	//if (type.endsWith("ExpandedMenuView") || type.endsWith("AlertController$RecycleListView")) { return EXPAND_MENU; }
	if (type.endsWith("ListView") || type.endsWith("ExpandedMenuView")) {
		ListView l = (ListView)v;
		if (l.getCount() == 0) return EMPTY_LIST;
		
		if (l.getAdapter().getClass().getName().endsWith("PreferenceGroupAdapter")) {
			return PREFERENCE_LIST;
		}
		
		switch (l.getChoiceMode()) {
			case ListView.CHOICE_MODE_NONE: return LIST_VIEW;
			case ListView.CHOICE_MODE_SINGLE: return SINGLE_CHOICE_LIST;
			case ListView.CHOICE_MODE_MULTIPLE: return MULTI_CHOICE_LIST;
		}
	}
	
	if (type.endsWith("AutoCompleteTextView")) return AUTOCOMPLETE_TEXTVIEW;
	if (type.endsWith("TextView")) return TEXT_VIEW;
	
	if (type.endsWith("ImageView")) return IMAGE_VIEW;
	if (type.endsWith("LinearLayout")) return LINEAR_LAYOUT;
	if (type.endsWith("RelativeLayout")) return RELATIVE_LAYOUT;
	if (type.endsWith("SlidingDrawer")) return SLIDING_DRAWER;
	if (type.endsWith("DrawerLayout")) return DRAWER_LAYOUT;
	
	if ((v instanceof WebView) || type.endsWith("WebView")) return WEB_VIEW;
	if (type.endsWith("TwoLineListItem")) return LIST_ITEM;
	if (type.endsWith("NumberPicker")) return NUMBER_PICKER;
	if (type.endsWith("NumberPickerButton")) return NUMBER_PICKER_BUTTON;
	
	String parentType = v.getClass().getSuperclass().getName();
	if (alreadyCalled == false && parentType != null) {
		System.out.print(">>>>>> " + parentType);
		return getSimpleType(v, parentType, true);
	}
	
	return "";
}
 
Example 10
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void updateDisplayState() {
	final State state = getDisplayState(this);

       mDefaultColor = SettingsActivity.getPrimaryColor(getActivity());
       int accentColor = SettingsActivity.getAccentColor();
       if (mLastMode == state.derivedMode &&  mLastSortOrder == state.derivedSortOrder
               && mLastShowSize == state.showSize
               && mLastShowFolderSize == state.showFolderSize
			&& mLastShowThumbnail == state.showThumbnail
			&& mLastShowHiddenFiles == state.showHiddenFiles
               && (mLastShowColor != 0 && mLastShowColor == mDefaultColor)
               && (mLastShowAccentColor != 0 && mLastShowAccentColor == accentColor))
		return;
       boolean refreshData = mLastShowHiddenFiles != state.showHiddenFiles;
	mLastMode = state.derivedMode;
       mLastSortOrder = state.derivedSortOrder;
	mLastShowSize = state.showSize;
	mLastShowFolderSize = state.showFolderSize;
	mLastShowThumbnail = state.showThumbnail;
	mLastShowHiddenFiles = state.showHiddenFiles;

       mLastShowColor = mDefaultColor;
       mProgressBar.setColor(mLastShowColor);
	mListView.setVisibility(state.derivedMode == MODE_LIST ? View.VISIBLE : View.GONE);
	mGridView.setVisibility(state.derivedMode == MODE_GRID ? View.VISIBLE : View.GONE);

	final int choiceMode;
	if (state.allowMultiple) {
		choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
	} else {
		choiceMode = ListView.CHOICE_MODE_NONE;
	}

	final int thumbSize;
	if (state.derivedMode == MODE_GRID) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
		mListView.setAdapter(null);
		mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mGridView.setAdapter(mAdapter);
		mGridView.setColumnWidth(thumbSize);
		mGridView.setNumColumns(GridView.AUTO_FIT);
		mGridView.setChoiceMode(choiceMode);
		mCurrentView = mGridView;
	} else if (state.derivedMode == MODE_LIST) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
		mGridView.setAdapter(null);
		mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mListView.setAdapter(mAdapter);
		mListView.setChoiceMode(choiceMode);
		mCurrentView = mListView;
	} else {
		throw new IllegalStateException("Unknown state " + state.derivedMode);
	}

       ((BaseActivity) getActivity()).upadateActionItems(mCurrentView);
	mThumbSize = new Point(thumbSize, thumbSize);

       if(refreshData) {
           onUserSortOrderChanged();
       }
}
 
Example 11
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void updateDisplayState() {
	final State state = getDisplayState(this);

       mDefaultColor = SettingsActivity.getPrimaryColor(getActivity());
       int accentColor = SettingsActivity.getAccentColor();
       if (mLastMode == state.derivedMode &&  mLastSortOrder == state.derivedSortOrder
               && mLastShowSize == state.showSize
               && mLastShowFolderSize == state.showFolderSize
			&& mLastShowThumbnail == state.showThumbnail
			&& mLastShowHiddenFiles == state.showHiddenFiles
               && (mLastShowColor != 0 && mLastShowColor == mDefaultColor)
               && (mLastShowAccentColor != 0 && mLastShowAccentColor == accentColor))
		return;
       boolean refreshData = mLastShowHiddenFiles != state.showHiddenFiles;
	mLastMode = state.derivedMode;
       mLastSortOrder = state.derivedSortOrder;
	mLastShowSize = state.showSize;
	mLastShowFolderSize = state.showFolderSize;
	mLastShowThumbnail = state.showThumbnail;
	mLastShowHiddenFiles = state.showHiddenFiles;

       mLastShowColor = mDefaultColor;
       mProgressBar.setColor(mLastShowColor);
	mListView.setVisibility(state.derivedMode == MODE_LIST ? View.VISIBLE : View.GONE);
	mGridView.setVisibility(state.derivedMode == MODE_GRID ? View.VISIBLE : View.GONE);

	final int choiceMode;
	if (state.allowMultiple) {
		choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
	} else {
		choiceMode = ListView.CHOICE_MODE_NONE;
	}

	final int thumbSize;
	if (state.derivedMode == MODE_GRID) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
		mListView.setAdapter(null);
		mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mGridView.setAdapter(mAdapter);
		mGridView.setColumnWidth(thumbSize);
		mGridView.setNumColumns(GridView.AUTO_FIT);
		mGridView.setChoiceMode(choiceMode);
		mCurrentView = mGridView;
	} else if (state.derivedMode == MODE_LIST) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
		mGridView.setAdapter(null);
		mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mListView.setAdapter(mAdapter);
		mListView.setChoiceMode(choiceMode);
		mCurrentView = mListView;
	} else {
		throw new IllegalStateException("Unknown state " + state.derivedMode);
	}

       ((BaseActivity) getActivity()).upadateActionItems(mCurrentView);
	mThumbSize = new Point(thumbSize, thumbSize);

       if(refreshData) {
           onUserSortOrderChanged();
       }
}
 
Example 12
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void updateDisplayState() {
	final State state = getDisplayState(this);

       mDefaultColor = SettingsActivity.getPrimaryColor(getActivity());
       int accentColor = SettingsActivity.getAccentColor();
       if (mLastMode == state.derivedMode &&  mLastSortOrder == state.derivedSortOrder
               && mLastShowSize == state.showSize
               && mLastShowFolderSize == state.showFolderSize
			&& mLastShowThumbnail == state.showThumbnail
			&& mLastShowHiddenFiles == state.showHiddenFiles
               && (mLastShowColor != 0 && mLastShowColor == mDefaultColor)
               && (mLastShowAccentColor != 0 && mLastShowAccentColor == accentColor))
		return;
       boolean refreshData = mLastShowHiddenFiles != state.showHiddenFiles;
	mLastMode = state.derivedMode;
       mLastSortOrder = state.derivedSortOrder;
	mLastShowSize = state.showSize;
	mLastShowFolderSize = state.showFolderSize;
	mLastShowThumbnail = state.showThumbnail;
	mLastShowHiddenFiles = state.showHiddenFiles;

       mLastShowColor = mDefaultColor;
       mProgressBar.setColor(mLastShowColor);
	mListView.setVisibility(state.derivedMode == MODE_LIST ? View.VISIBLE : View.GONE);
	mGridView.setVisibility(state.derivedMode == MODE_GRID ? View.VISIBLE : View.GONE);

	final int choiceMode;
	if (state.allowMultiple) {
		choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL;
	} else {
		choiceMode = ListView.CHOICE_MODE_NONE;
	}

	final int thumbSize;
	if (state.derivedMode == MODE_GRID) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.grid_width);
		mListView.setAdapter(null);
		mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mGridView.setAdapter(mAdapter);
		mGridView.setColumnWidth(thumbSize);
		mGridView.setNumColumns(GridView.AUTO_FIT);
		mGridView.setChoiceMode(choiceMode);
		mCurrentView = mGridView;
	} else if (state.derivedMode == MODE_LIST) {
		thumbSize = getResources().getDimensionPixelSize(R.dimen.icon_size);
		mGridView.setAdapter(null);
		mGridView.setChoiceMode(ListView.CHOICE_MODE_NONE);
		mListView.setAdapter(mAdapter);
		mListView.setChoiceMode(choiceMode);
		mCurrentView = mListView;
	} else {
		throw new IllegalStateException("Unknown state " + state.derivedMode);
	}

       ((BaseActivity) getActivity()).upadateActionItems(mCurrentView);
	mThumbSize = new Point(thumbSize, thumbSize);

       if(refreshData) {
           onUserSortOrderChanged();
       }
}
 
Example 13
Source File: HListView.java    From Klyph with MIT License 4 votes vote down vote up
/**
 * Add a view as a child and make sure it is measured (if necessary) and positioned properly.
 * 
 * @param child
 *           The view to add
 * @param position
 *           The position of this child
 * @param x
 *           The x position relative to which this view will be positioned
 * @param flowDown
 *           If true, align left edge to x. If false, align right edge to x.
 * @param childrenTop
 *           Top edge where children should be positioned
 * @param selected
 *           Is this position selected?
 * @param recycled
 *           Has this view been pulled from the recycle bin? If so it does not need to be remeasured.
 */
private void setupChild( View child, int position, int x, boolean flowDown, int childrenTop, boolean selected, boolean recycled ) {
	final boolean isSelected = selected && shouldShowSelector();
	final boolean updateChildSelected = isSelected != child.isSelected();
	final int mode = mTouchMode;
	final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL && mMotionPosition == position;
	final boolean updateChildPressed = isPressed != child.isPressed();
	final boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

	// Respect layout params that are already in the view. Otherwise make some up...
	// noinspection unchecked
	AbsHListView.LayoutParams p = (AbsHListView.LayoutParams) child.getLayoutParams();
	if ( p == null ) {
		p = (AbsHListView.LayoutParams) generateDefaultLayoutParams();
	}
	p.viewType = mAdapter.getItemViewType( position );

	if ( ( recycled && !p.forceAdd ) || ( p.recycledHeaderFooter && p.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER ) ) {
		attachViewToParent( child, flowDown ? -1 : 0, p );
	} else {
		p.forceAdd = false;
		if ( p.viewType == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER ) {
			p.recycledHeaderFooter = true;
		}
		addViewInLayout( child, flowDown ? -1 : 0, p, true );
	}

	if ( updateChildSelected ) {
		child.setSelected( isSelected );
	}

	if ( updateChildPressed ) {
		child.setPressed( isPressed );
	}

	if ( mChoiceMode != ListView.CHOICE_MODE_NONE && mCheckStates != null ) {
		if ( child instanceof Checkable ) {
			( (Checkable) child ).setChecked( mCheckStates.get( position ) );
		} else if ( android.os.Build.VERSION.SDK_INT >= 11 ) {
			child.setActivated( mCheckStates.get( position ) );
		}
	}

	if ( needToMeasure ) {
		int childHeightSpec = ViewGroup.getChildMeasureSpec( mHeightMeasureSpec, mListPadding.top + mListPadding.bottom, p.height );
		int lpWidth = p.width;
		int childWidthSpec;
		if ( lpWidth > 0 ) {
			childWidthSpec = MeasureSpec.makeMeasureSpec( lpWidth, MeasureSpec.EXACTLY );
		} else {
			childWidthSpec = MeasureSpec.makeMeasureSpec( 0, MeasureSpec.UNSPECIFIED );
		}
		child.measure( childWidthSpec, childHeightSpec );
	} else {
		cleanupLayoutState( child );
	}

	final int w = child.getMeasuredWidth();
	final int h = child.getMeasuredHeight();
	final int childLeft = flowDown ? x : x - w;

	if ( needToMeasure ) {
		final int childBottom = childrenTop + h;
		final int childRight = childLeft + w;
		child.layout( childLeft, childrenTop, childRight, childBottom );
	} else {
		child.offsetLeftAndRight( childLeft - child.getLeft() );
		child.offsetTopAndBottom( childrenTop - child.getTop() );
	}

	if ( mCachingStarted && !child.isDrawingCacheEnabled() ) {
		child.setDrawingCacheEnabled( true );
	}

	if( android.os.Build.VERSION.SDK_INT >= 11 ) {
		if ( recycled && ( ( (AbsHListView.LayoutParams) child.getLayoutParams() ).scrappedFromPosition ) != position ) {
			child.jumpDrawablesToCurrentState();
		}
	}
}
 
Example 14
Source File: AbsHListView.java    From Klyph with MIT License 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 #CHOICE_MODE_SINGLE} or {@link #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 == ListView.CHOICE_MODE_NONE ) {
		return;
	}

	// Start selection mode if needed. We don't need to if we're unchecking something.
	if ( android.os.Build.VERSION.SDK_INT >= 11 ) {
		if ( value && mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null ) {
			if ( mMultiChoiceModeCallback == null ||
					!((MultiChoiceModeWrapper)mMultiChoiceModeCallback).hasWrappedCallback() ) {
				throw new IllegalStateException( "AbsListView: attempted to start selection mode " +
						"for CHOICE_MODE_MULTIPLE_MODAL but no choice mode callback was " +
						"supplied. Call setMultiChoiceModeListener to set a callback." );
			}
			mChoiceActionMode = startActionMode( (MultiChoiceModeWrapper)mMultiChoiceModeCallback );
		}
	}

	if ( mChoiceMode == ListView.CHOICE_MODE_MULTIPLE
			|| ( android.os.Build.VERSION.SDK_INT >= 11 && mChoiceMode == ListView.CHOICE_MODE_MULTIPLE_MODAL ) ) {
		boolean oldValue = mCheckStates.get( position );
		mCheckStates.put( position, value );
		if ( mCheckedIdStates != null && mAdapter.hasStableIds() ) {
			if ( value ) {
				mCheckedIdStates.put( mAdapter.getItemId( position ), position );
			} else {
				mCheckedIdStates.delete( mAdapter.getItemId( position ) );
			}
		}
		if ( oldValue != value ) {
			if ( value ) {
				mCheckedItemCount++;
			} else {
				mCheckedItemCount--;
			}
		}
		if ( mChoiceActionMode != null ) {
			final long id = mAdapter.getItemId( position );
			((MultiChoiceModeWrapper)mMultiChoiceModeCallback).onItemCheckedStateChanged( (ActionMode) mChoiceActionMode, position, id, value );
		}
	} else {
		boolean updateIds = mCheckedIdStates != null && mAdapter.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( mAdapter.getItemId( position ), position );
			}
			mCheckedItemCount = 1;
		} else if ( mCheckStates.size() == 0 || !mCheckStates.valueAt( 0 ) ) {
			mCheckedItemCount = 0;
		}
	}

	// Do not generate a data change while we are in the layout phase
	if ( !mInLayout && !mBlockLayoutRequests ) {
		mDataChanged = true;
		rememberSyncState();
		requestLayout();
	}
}
 
Example 15
Source File: AbsHListView.java    From Klyph with MIT License 3 votes vote down vote up
/**
 * Returns the checked state of the specified position. The result is only valid if the choice mode has been set to
 * {@link #CHOICE_MODE_SINGLE} or {@link #CHOICE_MODE_MULTIPLE}.
 * 
 * @param position
 *           The item whose checked state to return
 * @return The item's checked state or <code>false</code> if choice mode is invalid
 * 
 * @see #setChoiceMode(int)
 */
public boolean isItemChecked( int position ) {
	if ( mChoiceMode != ListView.CHOICE_MODE_NONE && mCheckStates != null ) {
		return mCheckStates.get( position );
	}

	return false;
}
 
Example 16
Source File: AbsHListView.java    From Klyph with MIT License 3 votes vote down vote up
/**
 * Returns the set of checked items in the list. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE}.
 * 
 * @return A SparseBooleanArray which will return true for each call to get(int position) where position is a position in the
 *         list, or <code>null</code> if the choice mode is set to {@link #CHOICE_MODE_NONE}.
 */
public SparseBooleanArray getCheckedItemPositions() {
	if ( mChoiceMode != ListView.CHOICE_MODE_NONE ) {
		return mCheckStates;
	}
	return null;
}