Java Code Examples for android.widget.ListView#CHOICE_MODE_MULTIPLE

The following examples show how to use android.widget.ListView#CHOICE_MODE_MULTIPLE . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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 2
private void setGroupMode(boolean groupMode) {
    setTitle(groupMode ? R.string.add_people : R.string.choose_friend);
    //mLayoutContactSelect.setVisibility(groupMode ? View.GONE : View.VISIBLE);
    //mLayoutGroupSelect.setVisibility(groupMode ? View.VISIBLE : View.GONE);

    int newChoiceMode = (groupMode ? ListView.CHOICE_MODE_MULTIPLE : ListView.CHOICE_MODE_SINGLE);
    if (mListView.getChoiceMode() != newChoiceMode) {
        mListView.setChoiceMode(newChoiceMode);
    }
    updateStartGroupChatMenu();
}
 
Example 3
private void setGroupMode(boolean groupMode) {
    setTitle(groupMode ? R.string.add_people : R.string.choose_friend);
    mLayoutContactSelect.setVisibility(groupMode ? View.GONE : View.VISIBLE);
    mLayoutGroupSelect.setVisibility(groupMode ? View.VISIBLE : View.GONE);
    int newChoiceMode = (groupMode ? ListView.CHOICE_MODE_MULTIPLE : ListView.CHOICE_MODE_SINGLE);
    if (mListView.getChoiceMode() != newChoiceMode) {
        mListView.setChoiceMode(newChoiceMode);
    }
    updateStartGroupChatMenu();
}
 
Example 4
Source Project: glimmr   File: PhotoGridFragment.java    License: Apache License 2.0 5 votes vote down vote up
public List<Photo> getSelectedPhotos() {
    List<Photo> ret = new ArrayList<Photo>();
    if (mGridView.getChoiceMode() != ListView.CHOICE_MODE_MULTIPLE) {
        Log.e(TAG, "PhotoGridFragment not in CHOICE_MODE_MULTIPLE");
        return ret;
    }
    SparseBooleanArray checkArray = mGridView.getCheckedItemPositions();
    for (int i=0; i < checkArray.size(); i++) {
        if (checkArray.valueAt(i)) {
            ret.add(mPhotos.get(checkArray.keyAt(i)));
        }
    }
    if (BuildConfig.DEBUG) Log.d(TAG, "getSelectedPhotos: " + ret.size());
    return ret;
}
 
Example 5
@Override
protected void onAttachedToWindow()
{
    super.onAttachedToWindow();
    
    // Check if there is a valid GUI element that can visualize the current
    // check-state.
    if (mCheckedTextView != null)
    {
        final ViewParent p = getParent();
        
        // Check if the parent of this list item is a ListView
        if (p instanceof ListView)
        {
            final int choiceMode = ((ListView) p).getChoiceMode();
            
            // Decide which check-state notation to visualize (check box,
            // radio button or none).
            switch (choiceMode)
            {
            case ListView.CHOICE_MODE_MULTIPLE:
                mCheckedTextView.setCheckMarkDrawable(mCheckDrawable);
                break;
            
            case ListView.CHOICE_MODE_SINGLE:
                mCheckedTextView.setCheckMarkDrawable(mRadioDrawable);
                break;
            
            default:
                mCheckedTextView.setCheckMarkDrawable(null);
                break;
            }
        }
    }
}
 
Example 6
/**
 * 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 7
Source Project: Klyph   File: AbsHListView.java    License: 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 8
/**
 * Check if we are currently in multi selection mode
 */
public boolean isMultiSelecting() {
	return isSelecting() && mGridView.getChoiceMode() == ListView.CHOICE_MODE_MULTIPLE;
}