Android viewpager + fragment: select the current fragment to trigger some more things. viewpagerfragment

Source: Internet
Author: User

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.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.