Package com.amrdeveloper.treeview
Class TreeViewAdapter
java.lang.Object
androidx.recyclerview.widget.RecyclerView.Adapter<TreeViewHolder>
com.amrdeveloper.treeview.TreeViewAdapter
public class TreeViewAdapter
extends androidx.recyclerview.widget.RecyclerView.Adapter<TreeViewHolder>
Custom RecyclerView.Adapter used to provide a tree view features on any RecyclerView
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface definition for a callback to be invoked when a TreeNode has been clicked and held.static interfaceInterface definition for a callback to be invoked when a TreeNode has been clicked and held.Nested classes/interfaces inherited from class androidx.recyclerview.widget.RecyclerView.Adapter
androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy -
Constructor Summary
ConstructorsConstructorDescriptionTreeViewAdapter(TreeViewHolderFactory factory) Simple constructorTreeViewAdapter(TreeViewHolderFactory factory, TreeNodeManager manager) Constructor used to accept user custom TreeNodeManager class -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete all tree nodesvoidCollapsing all nodes in the tree with their childrenvoidcollapseNode(TreeNode node) Collapsing node and all of his childrenvoidcollapseNodeBranch(TreeNode node) Collapsing full node branchesvoidExpanding all nodes in the tree with their childrenvoidexpandNode(TreeNode node) Expanding node and all of his childrenvoidexpandNodeBranch(TreeNode node) Expanding node full branchesvoidexpandNodesAtLevel(int level) Expanding all tree nodes branches to until specific levelvoidexpandNodeToLevel(TreeNode node, int level) Expanding one node branch to until specific levelintintgetItemViewType(int position) Get the Current visible Tree nodesvoidonBindViewHolder(TreeViewHolder holder, int position) onCreateViewHolder(ViewGroup parent, int layoutId) voidRegister a callback to be invoked when this TreeNode is clickedvoidRegister a callback to be invoked when this TreeNode is clicked and heldvoidsetTreeNodes(List<TreeNode> treeNodes) Set the current visible tree nodes and notify adapter datavoidupdateTreeNodes(List<TreeNode> treeNodes) Update the list of tree nodesMethods inherited from class androidx.recyclerview.widget.RecyclerView.Adapter
bindViewHolder, createViewHolder, findRelativeAdapterPositionIn, getItemId, getStateRestorationPolicy, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, setStateRestorationPolicy, unregisterAdapterDataObserver
-
Constructor Details
-
TreeViewAdapter
Simple constructor- Parameters:
factory- a View Holder Factory mapped with layout id's
-
TreeViewAdapter
Constructor used to accept user custom TreeNodeManager class- Parameters:
factory- a View Holder Factory mapped with layout id'smanager- a custom tree node manager class
-
-
Method Details
-
onCreateViewHolder
- Specified by:
onCreateViewHolderin classandroidx.recyclerview.widget.RecyclerView.Adapter<TreeViewHolder>
-
onBindViewHolder
- Specified by:
onBindViewHolderin classandroidx.recyclerview.widget.RecyclerView.Adapter<TreeViewHolder>
-
getItemViewType
public int getItemViewType(int position) - Overrides:
getItemViewTypein classandroidx.recyclerview.widget.RecyclerView.Adapter<TreeViewHolder>
-
getItemCount
public int getItemCount()- Specified by:
getItemCountin classandroidx.recyclerview.widget.RecyclerView.Adapter<TreeViewHolder>
-
collapseNode
Collapsing node and all of his children- Parameters:
node- The node to collapse it
-
expandNode
Expanding node and all of his children- Parameters:
node- The node to expand it
-
collapseNodeBranch
Collapsing full node branches- Parameters:
node- The node to collapse it
-
expandNodeBranch
Expanding node full branches- Parameters:
node- The node to expand it
-
expandNodeToLevel
Expanding one node branch to until specific level- Parameters:
node- to expand branch of it until levellevel- to expand node branches to it
-
expandNodesAtLevel
public void expandNodesAtLevel(int level) Expanding all tree nodes branches to until specific level- Parameters:
level- to expand all nodes branches to it
-
collapseAll
public void collapseAll()Collapsing all nodes in the tree with their children -
expandAll
public void expandAll()Expanding all nodes in the tree with their children -
updateTreeNodes
Update the list of tree nodes- Parameters:
treeNodes- The new tree nodes
-
clearTreeNodes
public void clearTreeNodes()Delete all tree nodes -
setTreeNodeClickListener
Register a callback to be invoked when this TreeNode is clicked- Parameters:
listener- The callback that will run
-
setTreeNodeLongClickListener
Register a callback to be invoked when this TreeNode is clicked and held- Parameters:
listener- The callback that will run
-
setTreeNodes
Set the current visible tree nodes and notify adapter data- Parameters:
treeNodes- New tree nodes
-
getTreeNodes
Get the Current visible Tree nodes- Returns:
- The visible Tree nodes main
-
getSelectedNode
- Returns:
- The current selected TreeNode
-