I recently added Fragments to my applications. For a new application i'll need to get notified as soon as my fragment is shown. So i can do some calculations as soon as my fragment is shown again.
My Fragment is used with a TabIndicator and it's only one FragmentClass which is used a few times.
Here's the normal standard override class:
@Override public void onHiddenChanged(boolean hidden) { super.onHiddenChanged(hidden); }
These files contain only the onCreateView() method to inflate the UI of the fragment and returns the root of the fragment layout. If the fragment does not have any UI, it will return null.
onStop() is normally called when fragment becomes invisible, but it can also be called later in time. Depending on your layout Android can call onStart() even, when your Fragment is not yet visible, but it belongs to a visible parent container.
onCreateView() : The system calls this callback when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View component from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.
onStart()The onStart() method is called once the fragment gets visible. onResume()Fragment becomes active.
I had same problem.
I used standart guideline practic work with fragment (Building a Flexible UI). I have two fragment (ListItemsFragment and InfoItemFragment). When used normal screen size, I replace ListItemsFragment at InfoItemFragment and the method onHiddenChanged doesn't call automatic.
FragmentTransaction mFragmentTransaction = getFragmentManager().beginTransaction(); mFragmentTransaction.replace(R.id.container_fragment, new InfoItemFragment(), "tag_fr_infoItem"); mFragmentTransaction.addToBackStack(null); mFragmentTransaction.commit();
I think we must called in hide method FragmentTransaction. For example:
ListItemsFragment mListItemsFragment; FragmentTransaction mFragmentTransaction = getFragmentManager().beginTransaction(); mFragmentTransaction.replace(R.id.container_fragment, new InfoItemFragment(), "tag_fr_infoItem"); if (mListItemsFragment != null) { mFragmentTransaction.hide(mListItemsFragment); } mFragmentTransaction.addToBackStack(null); mFragmentTransaction.commit();
And now the method onHiddenChanged work fine. When user click back button mListItemsFragment again show and method onHiddenChanged called automatic.
In documentation said: this will be called whenever the fragment changes state from that
I think we must manual change value then method will be called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With