Java Code Examples for android.widget.ListView#CHOICE_MODE_SINGLE

The following examples show how to use android.widget.ListView#CHOICE_MODE_SINGLE . 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 check out the related API usage on the sidebar.
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
Source Project: LibreTasks   File: UtilUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Uncheck any item that is currently selected in a ListView.
 */
public static void uncheckListViewSingleChoice(ListView listView) {
  if (listView.getChoiceMode() == ListView.CHOICE_MODE_SINGLE) {
    int checkedPosition = listView.getCheckedItemPosition();
    if (checkedPosition > -1) {
      listView.setItemChecked(checkedPosition, false);
    }
  }
  else {
    throw new IllegalArgumentException(
      "UtilUI.uncheckListView() only works on lists using choice mode: CHOICE_MODE_SINGLE.");
  }
}
 
Example 4
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 5
Source Project: Klyph   File: AbsHListView.java    License: MIT License 5 votes vote down vote up
/**
 * Returns the currently checked item. The result is only valid if the choice mode has been set to {@link #CHOICE_MODE_SINGLE}.
 * 
 * @return The position of the currently checked item or {@link #INVALID_POSITION} if nothing is selected
 * 
 * @see #setChoiceMode(int)
 */
public int getCheckedItemPosition() {
	if ( mChoiceMode == ListView.CHOICE_MODE_SINGLE && mCheckStates != null && mCheckStates.size() == 1 ) {
		return mCheckStates.keyAt( 0 );
	}

	return INVALID_POSITION;
}
 
Example 6
@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 7
private boolean isGroupMode() {
  return mListView.getChoiceMode() != ListView.CHOICE_MODE_SINGLE;
}
 
Example 8
/**
 * 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 9
private boolean isGroupMode() {
  return mListView.getChoiceMode() != ListView.CHOICE_MODE_SINGLE;
}
 
Example 10
/**
 * Check if we are currently in single selection mode
 */
public boolean isSingleSelecting() {
	return isSelecting() && mGridView.getChoiceMode() == ListView.CHOICE_MODE_SINGLE;
}