Sets View.GONE or View.VISIBLE to the view visibility, this method is LAZY. - Android User Interface

Android examples for User Interface:View Hide Show

Description

Sets View.GONE or View.VISIBLE to the view visibility, this method is LAZY.

Demo Code


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

public class Main {
    /**//from  w w  w  .  j  a  va 2  s  .  c  o  m
     * Sets View.GONE or View.VISIBLE to the view visibility, this method is LAZY.
     * If current View's flag is equals to flag you want to set, it would not set it and View would
     * not be invalidated
     *
     * @param view
     *          object to show/hide, can be null
     * @param isVisible
     *          true to set View.VISIBLE flag, false to set View.GONE flag
     */
    public static void setVisibility(final View view,
            final boolean isVisible) {
        if (view == null)
            return;

        final int visibilityFlag = isVisible ? View.VISIBLE : View.GONE;

        if (view.getVisibility() != visibilityFlag) {
            view.setVisibility(visibilityFlag);
        }
    }
}

Related Tutorials