get All Children from ViewGroup - Android User Interface

Android examples for User Interface:ViewGroup

Description

get All Children from ViewGroup

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.List;
import android.view.View;
import android.view.ViewGroup;

public class Main {
    public static List<View> getAllChildren(ViewGroup top) {
        List<View> children = new ArrayList<View>();
        for (int i = 0; i < top.getChildCount(); i++) {
            View child = top.getChildAt(i);
            children.add(child);//from   ww w . j  a  v  a2 s  . co  m
            if (child instanceof ViewGroup)
                children.addAll(getAllChildren((ViewGroup) child));
        }
        return children;
    }
}

Related Tutorials