setVisibility() - Hide a Button, in Java

How to Hide a Button, in Java

Related XML Attribute: android:visibility

setVisibility() was added in API Level 1

1. Find the Button by ID named myButton.

2. In the MainActivity.java file, add the code below to the imports section.

import android.view.View;

3. In the MainActivity.java file, add the below line of code to the onCreate method.

myButton.setVisibility(View.GONE);

4. All options:

mybutton.setVisibility(View.VISIBLE);
mybutton.setVisibility(View.INVISIBLE);
mybutton.setVisibility(View.GONE);

5. Compile and run!

Related Articles:
References:
http://developer.android.com/reference/android/view/View.html#setVisibility(int)
stackoverflow.com/questions/7348150/android-why-setvisibilityview-gone-or-setvisibilityview-invisible-do-not