android - Fragments inside ViewPager dissapear when orientation changes -


i have read several posts (http://tinyurl.com/pb8es74, http://tinyurl.com/p9pcfcv...) cannot find solution.

i have mainactivity loads layout containing viewpager 3 fragments (which have different layouts depending on orientation).

i have added feature activity not destroyed when orientation changes might have dialogs or popips opened:

android:configchanges="keyboardhidden|orientation|screensize|screenlayout|uimode" 

therefore, have overwritten method "onconfigurationchanged" calls method loadlayout, regarding view made:

 private void loadlayout() {     setcontentview(r.layout.layout_main_activity);      pager = (viewpager) this.findviewbyid(r.id.pager);     pager.setpagetransformer(true, new depthpagetransformer());      adapter = new myfragmentpageradapter(getsupportfragmentmanager());     adapter.addfragment(fragment1.getinstance());     adapter.addfragment(fragment2.getinstance());     adapter.addfragment(fragment3.getinstance());      pager.setadapter(adapter);     pager.setoffscreenpagelimit(2);      //media controllers     imgmediacontroller= (imagebutton) findviewbyid(r.id.media_controller);      imgmediacontroller.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             [...]         }     });      imgvolumecontroller= (imagebutton) findviewbyid(r.id.volume_controller);     gm.setimgvolumecontroller(imgvolumecontroller);      imgvolumecontroller.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             [...]         }     }); } 

the code fragments equal:

public class fragmentnature extends fragment {  private static fragmentnature instance; private soundmanager sm; private view rootview; hashtable<string, imagebutton> h_images; private handler repeatupdatehandler = new handler(); private toast volumetoast;   public static fragmentnature getinstance() {     if (instance == null)         instance = new fragmentnature();     return instance; }  public void nullinstance() {     instance=null; }  public fragmentnature(){     h_images=new hashtable<string,imagebutton>(); }  public void oncreate(bundle savedinstancestate) {     log.d("naturing", "on create->estoy en el fragment nature");     super.onactivitycreated(savedinstancestate);     sm=soundmanager.getinstance(); }  public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {       rootview=null;     log.d("naturing", "on createview->estoy en el fragment nature");     rootview = inflater.inflate(r.layout.fragment_nature, container, false);      final imagebutton imgrain= (imagebutton) rootview.findviewbyid(r.id.n_rain);     h_images.put("n_rain",imgrain);     imgrain.setimageresource(r.drawable.n_rainsel);      final imagebutton imgriver= (imagebutton) rootview.findviewbyid(r.id.n_river);     imgriver.setimageresource(r.drawable.n_riversel);      final imagebutton imgwave= (imagebutton) rootview.findviewbyid(r.id.n_wave);     h_images.put("n_wave",imgwave);     imgwave.setimageresource(r.drawable.n_wavesel);      final imagebutton imgwind= (imagebutton) rootview.findviewbyid(r.id.n_wind);     h_images.put("n_wind", imgwind);     imgwind.setimageresource(r.drawable.n_windsel);      final imagebutton imgfire= (imagebutton) rootview.findviewbyid(r.id.n_fire);     h_images.put("n_fire", imgfire);     imgfire.setimageresource(r.drawable.n_firesel);      final imagebutton imgtree= (imagebutton) rootview.findviewbyid(r.id.n_tree);     h_images.put("n_tree", imgtree);     imgtree.setimageresource(r.drawable.n_treesel);      final imagebutton imgstorm= (imagebutton) rootview.findviewbyid(r.id.n_storm);     h_images.put("n_storm", imgstorm);     imgstorm.setimageresource(r.drawable.n_stormsel);      final imagebutton imgdrop= (imagebutton) rootview.findviewbyid(r.id.n_drop);     h_images.put("n_drop", imgdrop);     imgdrop.setimageresource(r.drawable.n_dropsel);      final imagebutton imgdeepsea= (imagebutton) rootview.findviewbyid(r.id.n_deepsea);     h_images.put("n_deepsea", imgdeepsea);     imgdeepsea.setimageresource(r.drawable.n_deepseasel);      return rootview; }  private boolean isnetworkavailable(){     context context=applicationmanager.getappcontext();     connectivitymanager connectivitymanager=             (connectivitymanager) context.getsystemservice(context.connectivity_service);     networkinfo activenetworkinfo= connectivitymanager.getactivenetworkinfo();     return activenetworkinfo != null && activenetworkinfo.isconnected(); }  public void changeimagestatus(string sound, int imgid){     log.d("naturing", "fragmentnature::changeimagestatus  | sound= " + sound + "  imgid=" + imgid);     h_images.get(sound).setimageresource(imgid); } 

}

the problem when orientation changes, mainactivity layout correctly loaded, viewpager not. in fact dissapears , nothing can seen in place. anyway, viewpager there able go through , reach end (i know because can see blue sign when reach end of menu , so).

i have tried call oncreateview method of fragments nothing changes.

any idea? , kind regards

edit 1

if take out "pager.setoffscreenpagelimit(2);", after orientation changes, fragment 1 , fragment 3 visible when scroll viewpager while, fragment 2 not appear in case. know not in case gives hint anyone.

edit 2

if take out line in manifest, works ok calls oncreateview of mainactivity , fragment. need line in manifest.

in end did dialogfragments, because needed go ahead. anyway, great if knows how overcome problem in way explained in question future developments.

thanks


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -