private void handleClick(final int adapterPos) {
            if (adapterPos < 0 || adapterPos >= getItems().size()) {
                Log.e("adapterPos outside of list range: " + adapterPos + " >= " + getItems().size() + ": " + getItems());
                return;
            }
            final ListItem itemData = getItems().get(adapterPos);
            boolean selectionChanged = false;
            final Set<Object> newSelection = new HashSet<>(model.getSelectedItems());

            switch (itemData.type) {
                case SELECT_ALL:
                    if (model.getSelectedItems().size() == model.getItems().size()) {
                        newSelection.clear();
                    } else {
                        newSelection.addAll(model.getItems());
                    }
                    selectionChanged = true;
                    break;
                case SELECTED_VISIBLE:
                    final boolean remove = (currentlyVisible == currentlyVisibleSelected);
                    for (ListItem item : getOriginalItems()) {
                        if (item.type == ListItemType.ITEM && item.isVisible) {
                            if (remove) {
                                newSelection.remove(item.value);
                            } else {
                                newSelection.add(item.value);
                            }
                            selectionChanged = true;
                        }
                    }
                    break;
                case GROUPHEADER:
                    toggleGroupExpanded(itemData.itemGroup.getGroup());
                    break;
                case ITEM:
                default:
                    // data element
                    final Object itemValue = itemData.value;
                    final boolean itemIsSelected = newSelection.contains(itemValue);
                    if (model.getChoiceMode() == SimpleItemListModel.ChoiceMode.MULTI_CHECKBOX) {
                        if (itemIsSelected) {
                            newSelection.remove(itemValue);
                        } else {
                            newSelection.add(itemValue);
                        }
                    } else {
                        if (!newSelection.contains(itemValue)) {
                            newSelection.clear();
                            newSelection.add(itemValue);
                        }
                    }
                    selectionChanged = true;
            }
            if (selectionChanged) {
                model.setSelectedItems(newSelection);
            }
        }
This view displays and maintains a list of simple view items, mainly for (single or multiple)
item selection lists. It provides special support for grouping, filtering and "select all" for such
lists.
main/src/main/java/cgeo/geocaching/ui/SimpleItemListView.java