Skip to content

Instantly share code, notes, and snippets.

@alphamu
Created November 4, 2013 12:32
Show Gist options
  • Save alphamu/7301820 to your computer and use it in GitHub Desktop.
Save alphamu/7301820 to your computer and use it in GitHub Desktop.
Android get all views with a tag
public 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