-
-
Save louisbl/9227833 to your computer and use it in GitHub Desktop.
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
package com.onavo.android.common.ui; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import java.util.LinkedList; | |
import java.util.List; | |
/** | |
* Based on http://stackoverflow.com/a/8831593/37020 by by Shlomi Schwartz | |
* License: MIT | |
*/ | |
public class ViewGroupUtils { | |
public static List<View> getViewsByTag(View root, String tag) { | |
List<View> result = new LinkedList<View>(); | |
if (root instanceof ViewGroup) { | |
final int childCount = ((ViewGroup) root).getChildCount(); | |
for (int i = 0; i < childCount; i++) { | |
result.addAll(getViewsByTag(((ViewGroup) root).getChildAt(i), tag)); | |
} | |
} | |
final Object rootTag = root.getTag(); | |
// handle null tags, code from Guava's Objects.equal | |
if (tag == rootTag || (tag != null && tag.equals(rootTag))) { | |
result.add(root); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment