get All Child View - Android User Interface

Android examples for User Interface:View Child

Description

get All Child View

Demo Code

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

import android.view.View;
import android.view.ViewGroup;

public class Main {
  public static List<View> getAllChildView(View view) {
    List<View> allChildView = new ArrayList<View>();
    if (view instanceof ViewGroup) {
      ViewGroup vg = (ViewGroup) view;//  ww w.  j a va  2  s  .  co  m
      for (int i = 0; i < vg.getChildCount(); i++) {
        View viewChild = vg.getChildAt(i);
        allChildView.add(viewChild);
        allChildView.addAll(getAllChildView(viewChild));
      }
    }
    return allChildView;
  }
}

Related Tutorials