Android viewpager + fragment: select the current fragment to trigger some more things. viewpagerfragment
Recently encountered a problem in the project:
Background: Use viewpager + fragment to slide the homepage. Then, the dialog box is automatically displayed when the third fragment is selected.
Solution:
1.
Vp. setOnPageChangeListener (new OnPageChangeListener () {@ Override public void onPageSelected (int arg0) {// arg0 is the position of the selected fragment and can process some services. }
}
2. frgment provides a method
@ Override public void setUserVisibleHint (boolean isVisibleToUser) {LogUtil. I ("TAG", "setUserVisibleHint (" + isVisibleToUser + ")"); // when the display status is true, invisible to false if (isVisibleToUser) {} super. setUserVisibleHint (isVisibleToUser );}
3. Put the view list in viewpager, and bind the corresponding fragment when no view is selected.
When android uses viewpager and fragment for the tab effect, how does one process the corresponding content of each label in fragment,
You can use this. getActivity () to obtain the context object of the Activity and perform operations like Activity.
In Fragment, viewPager is used to embed three subFragment instances.
The data is being saved, and the adapter is created in the onAttach event. However, the view on the interface is rebuilt once. I have no data operation methods in onresume and onStart. Is empty. I load the onViewCreated event or restore it to the view.