Get all children view from View - Android User Interface

Android examples for User Interface:View Child

Description

Get all children view from View

Demo Code


//package com.java2s;

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<View> children(@NonNull final View view) {
        final List<View> views = new ArrayList<>();
        final ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            final View v = viewGroup.getChildAt(i);
            views.add(v);//w w w.  jav  a 2s  .  c  om
        }
        return views;
    }
}

Related Tutorials