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 );}