/** * deselects an item and removes its position in the selections list * also takes an iterator to remove items from the map * * @param item the item to deselected * @param position the global position (or < 0 if the item is not displayed) * @param entries the iterator which is used to deselect all */ public void deselect(Item item, int position, @Nullable Iterator<Integer> entries) { item.withSetSelected(false); if (entries != null) { entries.remove(); } if (position >= 0) { mFastAdapter.notifyItemChanged(position); } if (mSelectionListener != null) { mSelectionListener.onSelectionChanged(item, false); } }
@Override public void onClick(View v, int position, FastAdapter<RadioButtonSampleItem> fastAdapter, RadioButtonSampleItem item) { if (!item.isSelected()) { Set<Integer> selections = fastAdapter.getSelections(); if (!selections.isEmpty()) { int selectedPosition = selections.iterator().next(); fastAdapter.deselect(); fastAdapter.notifyItemChanged(selectedPosition); } fastAdapter.select(position); } } }
/** * selects an item and remembers its position in the selections list * * @param adapter adapter holding this item (or it's parent) * @param item the item to select * @param position the global position (or < 0 if the item is not displayed) * @param fireEvent true if the onClick listener should be called * @param considerSelectableFlag true if the select method should not select an item if its not selectable */ public void select(IAdapter<Item> adapter, Item item, int position, boolean fireEvent, boolean considerSelectableFlag) { if (considerSelectableFlag && !item.isSelectable()) { return; } item.withSetSelected(true); mFastAdapter.notifyItemChanged(position); if (mSelectionListener != null) mSelectionListener.onSelectionChanged(item, true); if (mFastAdapter.getOnClickListener() != null && fireEvent) { mFastAdapter.getOnClickListener().onClick(null, adapter, item, position); } }
/** * opens the expandable item at the given position * * @param position the global position * @param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false */ public void expand(int position, boolean notifyItemChanged) { Item item = mFastAdapter.getItem(position); if (item != null && item instanceof IExpandable) { IExpandable expandable = (IExpandable) item; //if this item is not already expanded and has sub items we go on if (!expandable.isExpanded() && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) { IAdapter<Item> adapter = mFastAdapter.getAdapter(position); if (adapter != null && adapter instanceof IItemAdapter) { ((IItemAdapter<?, Item>) adapter).addInternal(position + 1, expandable.getSubItems()); } //remember that this item is now opened (not collapsed) expandable.withIsExpanded(true); //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { mFastAdapter.notifyItemChanged(position); } } } }
adapter.notifyItemChanged(position, payload);
mFastAdapter.notifyItemChanged(position);