Java tutorial
//package com.java2s; //License from project: Open Source License import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; public class Main { /** * Searches a {@link ViewGroup} for the first {@link ImageView} it can find in its child views. * * @param container The container {@link ViewGroup}. * @return The first {@link ImageView} in the {@code container ViewGroup} (counted by child * indexes), or {@code null} if no {@code ImageView} was found. */ public static ImageView findFirstImageView(ViewGroup container) { for (int i = 0; i < container.getChildCount(); i++) { View v = container.getChildAt(i); if (v instanceof ImageView) { return (ImageView) v; } else if (v instanceof ViewGroup) { return findFirstImageView((ViewGroup) v); } } return null; } }