Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { @SuppressWarnings({ "unchecked", "rawtypes" }) public static List subviews(Object o) { try { Method getChild = o.getClass().getMethod("getChildAt", int.class); getChild.setAccessible(true); Method getChildCount = o.getClass().getMethod("getChildCount"); getChildCount.setAccessible(true); List result = new ArrayList(8); int childCount = (Integer) getChildCount.invoke(o); for (int i = 0; i < childCount; i++) { result.add(getChild.invoke(o, i)); } return result; } catch (NoSuchMethodException e) { return Collections.EMPTY_LIST; } catch (IllegalArgumentException e) { return Collections.EMPTY_LIST; } catch (IllegalAccessException e) { return Collections.EMPTY_LIST; } catch (InvocationTargetException e) { return Collections.EMPTY_LIST; } } }