android - Fragments in viewpager -


i have viewpager fragments , set each fragment model class according ui of fragment should edited. model class set fragment @ constructor before add fragment fragmentstatepageradapter. problem after rotating screen or when system kills application , restore it, fragment recreated system , model class instance lost. if set new fragmentstatepageradapter, fragments created system visible. there right way of achive create new instances of fragments , place them viewpager? tried many thinks removing fragments fragmentmanager, adding adapter viewpager again, change fragmentstatepageradapter fragmentpageradapter , nothing helped.

my activity class loading model classes in loader resource:

        list<fragment> visiblefragment = new arraylist<fragment>();         (screen screen : wizard.screens) {             if (screen.visible) {                 visiblefragment.add(new screenui(screen));             }         }         viewpager.setadapter(null);         viewpager.setadapter(new wizardpageradapter(getsupportfragmentmanager(), visiblefragment)); 

my fragmentstatepageradapter

public class wizardpageradapter extends fragmentpageradapter { private final list<fragment> mfragments; private final int count;  public wizardpageradapter(fragmentmanager fm, list<fragment> fragments) {     super(fm);     mfragments = fragments;     count = mfragments.size(); }  @override public fragment getitem(int index) {     return mfragments.get(index); }  @override public int getcount() {     return count; } } 

try add in manifest android:configchanges="orientation|keyboardhidden|screensize" activity.

or that

public class viewpagertaskadapter extends fragmentstatepageradapter { map<integer, fragmentviewtask> fragmentstask = new hashmap<integer, fragmentviewtask>(); @override     public fragment getitem(int arg0) {         fragmentviewtask myfragment = fragmentviewtask.newinstance(arg0,                 tasks.get(arg0));         fragmentstask.put(arg0, myfragment);         return myfragment;     }      @override     public void destroyitem(viewgroup container, int position, object object) {         super.destroyitem(container, position, object);         fragmentstask.remove(position);     }         public fragmentviewtask getfragment(int key) {         return fragmentstask.get(key);     }      @override     public int getcount() {         if (tasks != null)             return tasks.size();          return 0;     }  } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -