Set and Get Visibility Of View’s

mudassir khanmudassir khan
1 min read

Table of contents

A View is a simple building block of a user interface. It is a small rectangular box that can be TextView, EditText, or even a button. It occupies the area on the screen in a rectangular area and is responsible for drawing and event handling. View is a superclass of all the graphical user interface components.

A View’s visibility status is of Integer type and can have one of three options:

VISIBLE (0) - The View is visible to the user INVISIBLE (4) - The View is invisible to the user, but still takes up space in the layout GONE (8) - The View is invisible, and it does not take up space in the layout.

Usage:

Btn1= (Button) findViewById(R.id.btn); Btn2= (Button) findViewById(R.id.btn2); Btn3= (Button) findViewById(R.id.btn3);

Example : myBtn1.setVisibility(View.GONE); myBtn2.setVisibility(View.VISIBLE); myBtn3.setVisibility(View.INVISIBLE);

We can get view visibility by getVisibility()

Example : Btn1.getVisibility()

If (Btn1.getVisibility() == View.VISIBLE) { Btn2.setVisibility(View.GONE) Btn3.setVisibility(View.GONE) }

0
Subscribe to my newsletter

Read articles from mudassir khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

mudassir khan
mudassir khan