Skip to content

Instantly share code, notes, and snippets.

@ultra-taco
Created June 25, 2019 21:49
Show Gist options
  • Save ultra-taco/f6996f0ec428893f61360aded7d402e2 to your computer and use it in GitHub Desktop.
Save ultra-taco/f6996f0ec428893f61360aded7d402e2 to your computer and use it in GitHub Desktop.
@JvmStatic
fun getAllChildren(v: View, recursive: Boolean, ignoredElements: List<View>): ArrayList<View> {
if (v !is ViewGroup || v.childCount == 0) {
val r = ArrayList<View>()
r.add(v)
return r
} else {
val list = ArrayList<View>()
list.add(v)
val children = v.childCount
for (i in 0 until children) {
val child = v.getChildAt(i)
if (!ignoredElements.contains(child)) {
if (recursive) {
list.addAll(getAllChildren(child, recursive, ignoredElements))
} else {
list.add(child)
}
}
}
return list
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment