Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2017 15:51
Show Gist options
  • Save anonymous/a46f00c1e34b361a51c3eec51fde313d to your computer and use it in GitHub Desktop.
Save anonymous/a46f00c1e34b361a51c3eec51fde313d to your computer and use it in GitHub Desktop.
TreeRv
private int sum;
private void findViewPositionForNode(List<TreeNode> nodes, TreeNode targetNode, IResult r) {
for (int i = 0; i < nodes.size(); i++) {
TreeNode node = nodes.get(i);
sum++;
if (node == targetNode) {
int result = sum - 1;
System.out.println("find target node:" + result);
sum = 0;
r.onResult(result);
break;
}
if (!node.isLeaf()) {
findViewPositionForNode(node.getChildList(), targetNode, r);
}
}
}
private void expandAll(List<TreeNode> treeNode) {
for (int i = 0; i < treeNode.size(); i++) {
TreeNode item = treeNode.get(i);
if (!item.isLeaf()) {
item.toggle();
expandAll(item.getChildList());
}
}
}
interface IResult {
void onResult(int targetPosition);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment