Created
November 4, 2013 12:32
-
-
Save alphamu/7301820 to your computer and use it in GitHub Desktop.
Android get all views with a tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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