Convert children Recursive to View List - Android User Interface

Android examples for User Interface:View Child

Description

Convert children Recursive to View List

Demo Code


//package com.java2s;

import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<View> childsRecursive(ViewGroup v) {
        ArrayList<View> views = new ArrayList<>();
        for (int i = 0; i < v.getChildCount(); i++) {
            if (v.getChildAt(i) instanceof ViewGroup) {
                views.add(v.getChildAt(i));
                childsRecursive((ViewGroup) v.getChildAt(i));
            } else {
                views.add(v.getChildAt(i));
            }//from  w w  w  .  j av a 2  s .c o  m
        }
        return views;
    }
}

Related Tutorials