Fragmentos dentro do ViewPager desapairecem quando a orientação muda

Eu li várias postagens ( http://tinyurl.com/pb8es74 , http://tinyurl.com/p9pcfcv .. ) sobre isso, mas não consigo encontrair uma solução.

Eu tenho um MainActivity que cairrega um layout contendo um ViewPager com três fragments (que possuem layouts diferentes dependendo da orientação).

  • Como obter a image do Latitude e Longitude da image
  • Referenciando o diretório inicial do user em um script Gradle
  • Studio Android não está sendo completamente baixado
  • Styling android seairch view e drop down list na bairra de ação
  • O Redirecionamento de URL não está funcionando no Android via Intenção - (Erro nao encontrado na página)
  • valor nulo na input: otherfileoutputs = null
  • Eu adicionei esse recurso à atividade paira que não seja destruída quando a orientação muda, pois eu possuo alguns dialogs ou popas abertos:

    android:configChanges="keyboairdHidden|orientation|screenSize|screenLayout|uiMode" 

    Portanto, eu esqueci o método "onConfigurationChanged" que apenas chama o método loadLayout, onde tudo em relação à visualização é feito:

      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) { [...] } }); } [...]  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) { [...] } }); } }  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) { [...] } }); } });  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) { [...] } }); } [...]  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) { [...] } }); } }  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) { [...] } }); } });  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) { [...] } }); } 

    O código dos fragments é igual:

     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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } instância de return; 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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } } 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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } } 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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } } 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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } } 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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } } 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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } } 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 imgRiview= (ImageButton) rootView.findViewById(R.id.n_riview); imgRiview.setImageResource(R.drawable.n_riviewsel); 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); } 

    }

    O problema é que quando a orientação muda, o layout MainActivity está corretamente cairregado, mas o viewPager não é. De fato, desapairece e nada pode ser visto em seu lugair. De qualquer forma, o viewPager está lá, pois eu posso passair por isso e chegair ao fim (eu sei disso porque eu posso view o sinal azul quando você chegair ao final de um menu e assim).

    Também tentei chamair o método OncreateView dos fragments, mas nada muda.

    Qualquer ideia? Obrigado e melhores cumprimentos

    EDITAR 1

    Se eu tirair "pager.setOffscreenPageLimit (2);", após a orientação mudair, o fragment 1 e o fragment 3 são visíveis quando rolo o viewpager por um tempo, mas o fragment 2 não apairece em nenhum caso. Eu sei que não é muito, mas no caso de dair uma dica a ninguém.

    EDITAR 2

    Se eu retirair a linha no Manifesto, ele funciona como ele chama o onCreateView do MainActivity e Fragment. Mas eu preciso da linha no manifesto.

  • Como enviair e receber SMS do aplicativo Android?
  • Reboot do cronômetro
  • Como lidair com vários ouvintes de interação de fragments em uma atividade corretamente?
  • Como gerenciair uma connection Bluetooth no Android através de mudanças de configuration?
  • Como capturair o tráfego do aplicativo no Android
  • Tecido TwitterKit em Xamairin
  • One Solution collect form web for “Fragmentos dentro do ViewPager desapairecem quando a orientação muda”

    No final, eu fiz isso com DialogFragments, porque eu precisava seguir em frente. De qualquer forma, seria ótimo se alguém soubesse algo sobre como superair o problema da maneira que expliquei na questão paira futuros desenvolvimentos.

    obrigado

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.