Reputation: 120
i have this problem the method OnCreateView of my Fragment is called twice when the user rotates the device and it changes all the values in the second call, here is the code of this fragment, i just create this fragment if the saveInstanceState of previous fragment is null.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view =inflater.inflate(R.layout.fragment_datos_reborn, container, false);
setRetainInstance(true);
//declaracion de fragment de resultados
if (getFragmentManager().findFragmentByTag("resultados_fragment")==null){
resultadosFragment=new ResultadosFragment();
}
view.findViewById( R.id.aceptarDatos).setOnClickListener(this);
//Asignaciones de RadioGroup del tipo de regresión
mRGTipoDeRegresion=(RadioGroup)view.findViewById(R.id.rGTipoDeRegresion);
rBTipoLineal=(RadioButton)view.findViewById(R.id.rBLineal);
rBTipoLineal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tipoDeRegresion="lineal";
}
});
rBTipoPotencial=(RadioButton)view.findViewById(R.id.rBPotecial);
rBTipoPotencial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tipoDeRegresion="potencial";
}
});
//Se pregunta si es tablet
esTablet=getResources().getBoolean(R.bool.es_tablet);
//obtener recycler
recycler = (RecyclerView)view.findViewById(R.id.recyclerDatos);
recycler.setHasFixedSize(true);
mBundle=this.getArguments();
// if (savedInstanceState==null){
if (savedInstanceState==null){
ejecutadoDesdePul=mBundle.getInt("ejecutado_desde_pulsasion");
}else {
ejecutadoDesdePul=0;
}
// if (ejecutadoDesdePul==1){
if (savedInstanceState==null){
elementoFuePulsado=mBundle.getBoolean("elemento_pulsado");
botonAceptarFuePulsado=mBundle.getBoolean("botonAceptarPulsado");
}else {
elementoFuePulsado=false;
botonAceptarFuePulsado=false;
}
if(elementoFuePulsado==true){
numeroDeVariables=0;
variablesX=Funciones.convertirADoubleArrayComplejo(mBundle.getDoubleArray("valoresX"));
variablesY=Funciones.convertirADoubleArrayComplejo(mBundle.getDoubleArray("valoresY"));
elementoFuePulsado=false;
}else if(botonAceptarFuePulsado==true) {
numeroDeVariables=mBundle.getInt("numero_de_variables");
botonAceptarFuePulsado=false;
if (savedInstanceState==null){
if (giroPantalla!=true) {
variablesX = new Double[numeroDeVariables];
variablesY = new Double[numeroDeVariables];
giroPantalla=false;
}
}
}
tipoDeRegresion=mBundle.getString("tipo_de_regresion","");
etiquetaX=mBundle.getString("nombre_x");
etiquetaY=mBundle.getString("nombre_y");
if (savedInstanceState==null) {
poblarLista();
}
if (savedInstanceState==null){
if (tipoDeRegresion.equals("lineal")){
mRGTipoDeRegresion.check(R.id.rBLineal);
Funciones.hacerToastCorto(getActivity(),"Entra");
}else if (tipoDeRegresion.equals("potencial")){
mRGTipoDeRegresion.check(R.id.rBPotecial);
Funciones.hacerToastCorto(getActivity(),"Entra");
}
pasarAResultados();
}
if (ejecutadoDesdePul>=1){
ejecutadoDesdePul++;
}
return view;
}
Upvotes: 0
Views: 510