Reputation: 789
I've design the user interface of my app as a collection of views, not activities or fragments. I manage the showing and hiding of views on this collection of views which are right on top of each other.
I believe I chose the wrong design principle to use for my app. The problem I am having is that when I hide a view in order to show another one; the button that resides on the hidden view fires its on-Click listener.
After reading some of the Android Reference documentation, I see that the view tree will navigate down the hierarchy of views in order to consume the touch event. It is then that the on-Click listener of this button is called.
What I need is something to prevent the button from the hidden view to stop calling itself when the user touches the shown view. I know that calling setVisibility(View.INVISIBLE) stops the on-Click listener from being called.
I was thinking of the ViewTreeObserver class that will allow me to create a listener of view hierarchy that somehow allows me to get a handle of all the hidden views in order to call setVisibility(View.INVISIBLE) on the hidden views.
Any ideas or advice
Upvotes: 0
Views: 216
Reputation: 525
When you do setVisibility(View.INVISIBLE)
for a view, it will still present in the layout. So instead of setVisibility(View.INVISIBLE)
, try setVisibility(View.GONE)
.
This will remove the view completely from the layout including the onClickListner attached to it.
When you want that view back, you can use setVisibility(View.VISIBLE)
to get it back.
Upvotes: 1