Code example for SortedSet

Methods: add, clear

0
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					if (selectMode == ListView.CHOICE_MODE_SINGLE) {
						clearCheckedItems(); 
					} 
					checkedVariables.add(position);
				} else { 
					checkedVariables.remove(position);
				} 
				if (onCheckedChangeListener != null) {
					onCheckedChangeListener.onCheckedChange();
				} 
				notifyDataSetChanged();
			} 
		}); 
 
		if (checkedVariables.contains(position)) { 
			holder.checkbox.setChecked(true); 
		} else { 
			holder.checkbox.setChecked(false); 
		} 
 
		return view; 
	} 
 
	@Override 
	public View getDropDownView(final int position, View convertView, ViewGroup parent) {
		UserVariable variable = getItem(position);
		View view = convertView;
		ViewHolder holder;
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
			holder = new ViewHolder();
			holder.text1 = (TextView) view.findViewById(android.R.id.text1);
			view.setTag(holder);
		} else if (view.getTag() instanceof ViewHolder) {
			holder = (ViewHolder) view.getTag();
		} else { 
			holder = new ViewHolder();
			holder.text1 = (TextView) view.findViewById(android.R.id.text1);
			view.setTag(holder);
		} 
		holder.text1.setText(variable.getName());
		return view;
	} 
 
	@Override 
	public void setSelectMode(int selectMode) {
		this.selectMode = selectMode;
	} 
 
	@Override 
	public int getSelectMode() { 
		return selectMode;
	} 
 
	@Override 
	public void setShowDetails(boolean showDetails) {
	} 
 
	@Override 
	public boolean getShowDetails() { 
		return false; 
	} 
 
	@Override 
	public int getAmountOfCheckedItems() { 
		return checkedVariables.size();
	} 
 
	@Override 
	public SortedSet<Integer> getCheckedItems() {
		return checkedVariables;
	} 
 
	public List<UserVariable> getCheckedUserVariables() {
		List<UserVariable> vars = new ArrayList<UserVariable>();
		for (int pos : getCheckedItems()) {
			vars.add(getItem(pos));
		} 
		return vars;
	} 
 
	@Override 
	public void clearCheckedItems() { 
		checkedVariables.clear();
	} 
 
	public interface OnCheckedChangeListener { 
		public void onCheckedChange(); 
	}