Skip to content

Instantly share code, notes, and snippets.

@fanglinchen
Created March 3, 2016 02:15
Show Gist options
  • Save fanglinchen/cd02b1f61d08df351399 to your computer and use it in GitHub Desktop.
Save fanglinchen/cd02b1f61d08df351399 to your computer and use it in GitHub Desktop.
Loop through all subviews of an Android view
public void recursiveLoopChildren(ViewGroup parent) {
for (int i = parent.getChildCount() - 1; i >= 0; i--) {
final View child = parent.getChildAt(i);
if (child instanceof ViewGroup) {
recursiveLoopChildren((ViewGroup) child);
// DO SOMETHING WITH VIEWGROUP, AFTER CHILDREN HAS BEEN LOOPED
} else {
if (child != null) {
// DO SOMETHING WITH VIEW
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment