How do I make a button invisible just after click?
15,593
Solution 1
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Button button = (Button) v;
button.setVisibility(View.INVISIBLE);
}
});
This makes it go invisible but still take up space in the layout, switching the last row for:
button.setVisibility(View.GONE);
would make it "fold" and it will not only be invisible but won't take up space in the layuout either.
Solution 2
It's quite simple. setVisibility(View.Invisible)
inside OnClickListener()
of the button
Solution 3
put this line in your Button's on click method.
Button.setVisibility(View.INVISIBLE);
EDIT: if you make totally gone the Button view and then try
Button.setVisibility(View.GONE);
Solution 4
Just use this in your OnClickListener:
button.setVisibility(View.INVISIBLE);
If you want it to be totally invisible and take up layout space use
button.setVisibility(View.GONE);
Author by
Wahid
Updated on July 09, 2022Comments
-
Wahid almost 2 years
I would like to know how to make a button visible but when clicked I want it to be invisible so it won't be shown at all.