The getItem () method of FragmentPagerAdapter cannot obtain the solution of Fragment. pageradapter

Source: Internet
Author: User

The getItem () method of FragmentPagerAdapter cannot obtain the solution of Fragment. pageradapter

I have not solved this problem for one afternoon and cannot get the previous Fragment, because Fragment will continuously release resources.

In the end, the head was hot and TND was solved. The following code stores Fragment in a HashMap:



The Utils class code is as follows:


The setFragmentFromPosition method is to save Fragment;

The removeFragment method is used to delete unwanted Fragment from HashMap (this method is very important. If it is not called, memory overflow OutOfMemory will be reported due to HashMap );

The findViewFromFragment method is used to obtain the Fragment stored in the memory.

This is a success!



In android, how does one pass parameters when pageview + fragment is used as a dynamic album?

Fragment. setArguments (parameters to be passed in)
Then get the fragment. getArguments in onCreate.

How to apply multiple Fragment in ViewPager?

List fragments; public Fragment getItem (int pos) {return fragments. get (pos);} public void addFragment (Fragment f) {fragments. add (f );}

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.