fragmentos y onConfigurationChanged
Estoy tratando de hacer algo que hago con actividades, pero dentro de un fragmento. Lo que hago es usar actividades:
En primer lugar, la actividad se reinicia al girar el dispositivo.android:configChanges="keyboardHidden|orientation|screenSize"
en mi actividad añadir:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
}
Por lo tanto, la actividad no se reinicia, sino que se vuelve a cargar main.xml para usar layout-land
Ahora tengo una actividad que muestra viewpager, que contiene tres fragmentos. Todo funciona correctamente. La detección de la rotación está en los fragmentos.
public class FRG_map_web extends Fragment {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.i("myLogs", "Rotation");
}
El problema es que el fragmento no usa setContentView (R.layout.main); este es el codigo
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.frg.myFragment, null);
Traté de usar:
LayoutInflater inflater = inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.frg.myFragment, null);
...
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.frg.myFragment, null);
...
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
view = inflater.inflate(R.layout.frg.myFragment, null);
...
LayoutInflater li = LayoutInflater.from(context);
Y diferentes maneras, pero siempre sin éxito no puedo inflar correctamente.
¿Alguien puede decirme cómo tengo que hacer?
Gracias de antemano, agradezco la ayuda.
Saludos