hide All Children View Except - Android User Interface

Android examples for User Interface:View Child

Description

hide All Children View Except

Demo Code


//package com.java2s;

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

public class Main {
    public static void hideAllChildrenExcept(ViewGroup group,
            View... exceptions) {
        setVisibilityToAllChildrenExcept(group, View.GONE, exceptions);
    }/*from   w w w. j a v  a  2s.  co  m*/

    public static void setVisibilityToAllChildrenExcept(ViewGroup group,
            int visibility, View... exceptions) {
        for (int i = 0; i < group.getChildCount(); i++) {
            View child = group.getChildAt(i);

            boolean shouldApplyVisibility = true;

            for (View exception : exceptions) {
                if (exception == child) {
                    shouldApplyVisibility = false;
                    break;
                }
            }

            if (shouldApplyVisibility) {
                child.setVisibility(visibility);
            }
        }
    }
}

Related Tutorials