I have recently arrived at the world of programming and I am with a project of Android
.
I have two Fragments
in a Activity
in one of them you have to be listening if there is any change in the data that the user enters, if so, when you click on the Back button or Exit a message should appear with
"There are changes in the document you really want to leave".
The implementation that is now in the project is by Interface
public interface IDataFragment<E> {
boolean hayCambios();
}
This is one of the Fragments
that implements the Interface
public class DatosExtra extends Fragment implements IDataFragment<Shipment>{
public boolean cambiosDetectados = false;
//más código
//si hay cambios en alguno de los campos, por ejemplo si se modifica un spinner
cambiosDetectados = true;
@Override
public boolean hayCambios() {
return cambiosDetectados ;
}
}
And finally the Fragment that collects the changes does
public class MainFragment extends Fragment{
private Fragment datosExtra ;
//muestro mensaje de cambios?
if(haHabidoCambios())
mostrarMensaje();
//....
//....
private boolean haHabidoCambios() {
return ((IDataFragment)datosExtra).hasChanged();
}
....
}
But the case that does not always work, because sometimes when calling
Has changed ()
I get false, when it should be true and vice versa.
. I wonder if there is any way to make it clearer