Think I have 4 button on navbar.
First button contains some data or items and other buttons also contains some data or items.
Note: All four buttons under a same xml file.
I want if I click first button it will show me first button data or items and same time it will hide others three buttons data or items. And I want to use same method for all buttons.
How can I do that please help me.
3
Answers
As you want to hide other three buttons you can use switch case where you can get the click of the button and on the click of one button you can hide all other buttons.
when you define onclick method you will get the id of the clicked view.
You can achieve that by make all other button visibility GONE in onClick fun like that:
if you are in Activity
If you are in Fragment
In this example, when you press on a button he will be visible and all other will be gone from the UI.
You can you INVISIBLE instead of GONE, the different is that in GONE the view doesn’t "catchin" space in your screen, and INVISIBLE it does, just not visible to user (for more information read this)
As you want to hide data/items not buttons.if you hide button directly. you can’t click on that.
Suppose if you click on button1 and it hides other buttons. you can’t click on button2.
you have to put all data in a child layout which you can hide.
hide/show views in onClick method