Browse files

Changed view utile to return array list instead of array, and to neve…

…r return null
  • Loading branch information...
1 parent e0b019a commit df16bad8708caab03686fba0d384a7006ad9f4b7 @scruffyfox committed Nov 27, 2012
Showing with 11 additions and 8 deletions.
  1. +11 −8 src/x/util/ViewUtils.java
View
19 src/x/util/ViewUtils.java
@@ -6,9 +6,9 @@
package x.util;
import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.HashMap;
-import x.type.ItemList;
import android.view.View;
import android.view.ViewGroup;
@@ -73,11 +73,11 @@ public static String dump(Class R, int depth, View parent)
* Gets all views of a parent that match an instance (recursive)
* @param parent The parent view
* @param instance The instance to check
- * @return An array of views, or null
+ * @return An array of views
*/
- public static View[] getAllChildrenByInstance(ViewGroup parent, Class instance)
+ public static ArrayList<View> getAllChildrenByInstance(ViewGroup parent, Class... instance)
{
- ItemList<View> views = new ItemList<View>();
+ ArrayList<View> views = new ArrayList<View>();
int childCount = parent.getChildCount();
for (int childIndex = 0; childIndex < childCount; childIndex++)
@@ -86,18 +86,21 @@ public static String dump(Class R, int depth, View parent)
if (child instanceof ViewGroup)
{
- views.add(getAllChildrenByInstance((ViewGroup)child, instance));
+ views.addAll(getAllChildrenByInstance((ViewGroup)child, instance));
}
else
{
- if (child.getClass() == instance)
+ for (Class c : instance)
{
- views.add(child);
+ if (child.getClass() == c)
+ {
+ views.add(child);
+ }
}
}
}
- return views.size() > 0 ? (View[])views.toArray(new View[views.size()]) : null;
+ return views;
}
/**

0 comments on commit df16bad

Please sign in to comment.