Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.support.annotation.NonNull;

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

public class Main {
    @NonNull
    public static <T> List<T> childrenOfType(@NonNull View root, @NonNull Class<T> type) {
        final List<T> children = new ArrayList<>();
        if (type.isInstance(root)) {
            children.add(type.cast(root));
        }
        if (root instanceof ViewGroup) {
            final ViewGroup rootGroup = (ViewGroup) root;
            for (int i = 0; i < rootGroup.getChildCount(); i++) {
                final View child = rootGroup.getChildAt(i);
                children.addAll(childrenOfType(child, type));
            }
        }
        return children;
    }
}