Problem: Upon clicking a button in a fragment
inside of the ViewPager
the click falls through to the fragment
that is behind it and registers the onClickListener()
in the behind fragment
rather than the current fragment’s onClickListener()
.
Situation: I have a ViewPager
with 4 fragments
in it. Each fragment
contains a few rows of custom made buttons. Each fragment
has it’s own unique view/layout
, yet they are all designed similarly.
Set Up: I am using the FragmentPagerAdapter
, because I have a short list of pretty static fragments
AND because I need to communicate and update each fragment
by using an interface
, like how the developer docs suggest.
My Idea: Should I switch to the FragmentStatePagerAdapter
? So the adapter
will destroy the fragments
when they are not visible? But in doing this, will I not be able to communicate with the fragments
and update them accordingly?
I don’t know how to solve this problem and it has been driving me mad! Any help is appreciated.
Ask me if I need to clarify anything.
The reason that the
fragment
behind/after/to-the-right of the currentfragment
in theviewpager
was catching the button clicks was because of the use of thePageTransformer
class that I used to add a fade out animation to the pages upon sliding. ThisPageTransformer
animation messed everything up on android version 4.1.1 API 16 and version 4.2.2 API 17. SO be weary of usingPageTransformer
, especially if you want to support older android versions.