|
@@ -84,10 +84,18 @@ public class ViewUtils {
|
84
|
84
|
}
|
85
|
85
|
}
|
86
|
86
|
|
|
87
|
+ public interface Matcher<T> {
|
|
88
|
+ boolean match(T child);
|
|
89
|
+ }
|
|
90
|
+
|
87
|
91
|
/**
|
88
|
92
|
* Returns the first instance of clazz in root
|
89
|
93
|
*/
|
90
|
94
|
@Nullable public static <T> T findChildByClass(ViewGroup root, Class clazz) {
|
|
95
|
+ return findChildByClass(root, clazz, null);
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Nullable public static <T> T findChildByClass(ViewGroup root, Class clazz, Matcher<T> matcher) {
|
91
|
99
|
for (int i = 0; i < root.getChildCount(); i++) {
|
92
|
100
|
View view = root.getChildAt(i);
|
93
|
101
|
if (clazz.isAssignableFrom(view.getClass())) {
|
|
@@ -95,9 +103,14 @@ public class ViewUtils {
|
95
|
103
|
}
|
96
|
104
|
|
97
|
105
|
if (view instanceof ViewGroup) {
|
98
|
|
- view = findChildByClass((ViewGroup) view, clazz);
|
|
106
|
+ view = (View) findChildByClass((ViewGroup) view, clazz, matcher);
|
99
|
107
|
if (view != null && clazz.isAssignableFrom(view.getClass())) {
|
100
|
|
- return (T) view;
|
|
108
|
+ if (matcher == null) {
|
|
109
|
+ return (T) view;
|
|
110
|
+ }
|
|
111
|
+ if (matcher.match((T) view)) {
|
|
112
|
+ return (T) view;
|
|
113
|
+ }
|
101
|
114
|
}
|
102
|
115
|
}
|
103
|
116
|
}
|