Problems that may occur when multiple viewpagers exist.

Source: Internet
Author: User

Problems that may occur when multiple viewpagers exist.

Due to the convenience of Fragment, many people are now using Fragment in large quantities. If you encounter problems during use today, record them and share them.


FragmentActivity is used when Fragment is used, especially when ViewPager is used. Because FramgmentManager is required,

This time, ViewPager is used in both fragment. In fact, I did not consider it at the beginning. Then the FramgmentManager of the FragmentActivity is used for processing. However, when the first page is opened, the second page is displayed. The content on the second page is empty. view the log, the onCreatView method of the subview of ViewPager on the second page is not called ..


Baidu found that the tag in the instantiateItem of PagerAdapter was used to query Fragment from FramgmentManager. If the tag is found, the previous one will be used directly instead of being created again,

PagerAdapter tags are generated based on your pagerID and index.


What is it about? It indicates that the first page has a Fragment with the same tag as the second page. That is, two fragment instances have the same parent id and index.

The same pagerID is used.


Then I think of the layout file that was directly copied at that time, so the id is the same and the id is changed to solve the problem.

The problem lies in two key points:

1. The same FramgmentManager instance is used.

2. The ViewPager id is the same.


Therefore, when using this container type control, try to make the id different. Otherwise, a similar problem may occur.



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: 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.