I have a view pager with 2 fragments. One of them has a blue screen that should be hidden once the fragment is selected. So, I want to grasp a pointer to this fragment that I can call a certain method on once the user selects this fragment. I have implemented the addOnPageChangeListener interface. I want to call that method, to hide the blue screen, in the onPageSelected call.
My question is how can I grasp a pointer to the current selected fragment?
I have tried the following:
AnswersFragment fragment = (AnswersFragment) getSupportFragmentManager().findFragmentByTag("android:switcher:" + this.pager + ":" + position);
if (fragment == null)
fragment = new AnswersFragment();
But it always returns null.
I have also tried to keep an instance variable called currentAnswerFragment, but it doesn't necessarily point to the current fragment as the view pager keeps track of 3 fragments at the same time.
Also, my model is not an array (or 2) of fragments. I call a function that initializes a fragment and return it. With that said, I can't use the index of the current item to get the fragment being displayed.