When using Viewpager+fragmentpageradapter, updating fragment data is not working,fragmentpageradapter Adding or reducing fragment, The previous fragment content update does not work and so on, some practice is to violently delete the fragment list, such as
list<fragment> fragments = Getsupportfragmentmanager (). getfragments (); for (int i = Fragments.size ()-1; I >= 0; i--) {Getsupportfragmentmanager (). BeginTransaction (). Remove (fragments.get (0));
There is also the practice is to rewrite the Fragmentpageradapter instantiateitem (viewgroup container, int position) method and so on, effective, although effective, but relatively coarse explosion.
Fragmentpageradapter. GetItem (int position) is not necessarily called at the time of update, so the fragment update is not valid, take a look at the code in Fragmentpageradapter's parent class Pageradapter Instantiateitem
Fragmentpageradapter in accordance with getitemid (int position) to determine whether the current position fragment exist, if present, will not be created and not updated, then let The Fragmentpageradapter update takes effect, that in Getitemid (int) returns a unique data ID based on the data, when the fragmentpageradapter is updated, the data ID is changed, Then fragment will call GetItem (int) to get the new fragment, to achieve the update effect
@Overridepublic long Getitemid (int position) {//Gets the current data of hashcode int hashcode = mdata.get (position). Hashcode (); return hashcode;}
Android fragmentpageradapter Update Data