Adds all children of viewGroup (recursively) into views . - Android User Interface

Android examples for User Interface:ViewGroup

Description

Adds all children of viewGroup (recursively) into views .

Demo Code

/* Athrun - Android automation testing Framework.
 Copyright (C) 2010-2012 TaoBao UI AutoMan Team

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., HuaXing road, Hangzhou,China. 
 Email:taichan@taobao.com,shidun@taobao.com,bingyang.djj@taobao.com
 *//*from ww  w  .j av  a  2 s  .c  om*/
//package com.java2s;

import java.util.ArrayList;

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

public class Main {
    /**
     * Adds all children of {@code viewGroup} (recursively) into {@code views}.
     * 
     * @param views
     *            an {@code ArrayList} of {@code View}s
     * @param viewGroup
     *            the {@code ViewGroup} to extract children from
     * @param onlySufficientlyVisible
     *            if only sufficiently visible views should be returned
     * 
     */
    static void addChildren(ArrayList<View> views, ViewGroup viewGroup,
            boolean onlySufficientlyVisible) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            final View child = viewGroup.getChildAt(i);

            if (onlySufficientlyVisible && child.isShown()) {
                views.add(child);

            } else if (!onlySufficientlyVisible) {
                views.add(child);
            }

            if (child instanceof ViewGroup) {
                addChildren(views, (ViewGroup) child,
                        onlySufficientlyVisible);
            }
        }
    }
}

Related Tutorials