Recursively enables/disables all the child group, and any children of any ViewGroup in that ViewGroup . - Android User Interface

Android examples for User Interface:ViewGroup

Description

Recursively enables/disables all the child group, and any children of any ViewGroup in that ViewGroup .

Demo Code


//package com.java2s;
import android.view.View;
import android.view.ViewGroup;

public class Main {
    /**//from   w  w  w .j  a  v  a  2s .  c om
     * Recursively enables/disables all the childs group, and any children of
     * any {@link ViewGroup} in that {@link ViewGroup}.
     * 
     * @param group The {@link ViewGroup} to enable/disable
     * @param enabled Whether the {@link ViewGroup} should be enabled/disabled
     */
    public static void setViewGroupEnabled(ViewGroup group, boolean enabled) {
        group.setEnabled(enabled);

        for (int i = 0; i < group.getChildCount(); i++) {
            View view = group.getChildAt(i);
            view.setEnabled(enabled);

            if (view instanceof ViewGroup) {
                setViewGroupEnabled((ViewGroup) view, enabled);
            }
        }
    }
}

Related Tutorials