Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Created January 8, 2016 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchuck/c837f554a9f2cc6bde05 to your computer and use it in GitHub Desktop.
Save Marchuck/c837f554a9f2cc6bde05 to your computer and use it in GitHub Desktop.
private static ArrayList<View> getViewsByTag(ViewGroup root, String tag){
ArrayList<View> views = new ArrayList<View>();
final int childCount = root.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = root.getChildAt(i);
if (child instanceof ViewGroup) {
views.addAll(getViewsByTag((ViewGroup) child, tag));
}
final Object tagObj = child.getTag();
if (tagObj != null && tagObj.equals(tag)) {
views.add(child);
}
}
return views;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment