Android examples for User Interface:View Child
get All Children View Of Type
//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> getAllChildrenOfType(View view, Class classType) { List<View> listViews = getAllChildren(view); List<View> result = new ArrayList<>(); for (View v : listViews) { if (classType.isInstance(v)) result.add(v);/*www . j av a 2 s . com*/ } return result; } public static List<View> getAllChildren(View view) { List<View> visited = new ArrayList<View>(); List<View> unvisited = new ArrayList<View>(); unvisited.add(view); while (!unvisited.isEmpty()) { View child = unvisited.remove(0); visited.add(child); if (!(child instanceof ViewGroup)) continue; ViewGroup group = (ViewGroup) child; final int childCount = group.getChildCount(); for (int i = 0; i < childCount; i++) unvisited.add(group.getChildAt(i)); } return visited; } }