0
I am using the simple model of Fragment. There is one that is the List, and another Viewer . Fragmentactivity :
if(pFragVisualizar==null){
pFragVisualizar = new FragVisualizar();
pFragVisualizar.configuraVisualizador(dados);
}
if (!isPortrait()) {
fragVisualizar = (FragVisualizar) getFragmentManager().findFragmentByTag("visualizar");
fragVisualizar.configuraVisualizador(dados);
}
Fragment :
public class FragVisualizar extends Fragment{
protected Dados dados;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate( ((ActCadastro) getActivity()).visualizarID, container, false);
}
public void configuraVisualizador(Dados dados){
this.dados= dados;
if(getView()!=null) {
dados.layout = getView().findViewById(R.id.cadastro_layout_principal);
dados.atualizarViews();
dados.restaurarEstado();
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if(dados!=null) {
dados.layout = view.findViewById(R.id.cadastro_layout_principal);
dados.atualizarViews();
dados.restaurarEstado();
}
}
}
When an item is selected from the list, it displays the pFragView if you are Vertical, or just change the content of fragVisualize , if horizontal. And transmits a Data instance that puts the values in the views. In the vertical the onCreateView happens after configurationVisualizador, already in the horizontal happens the opposite.
The problem is that if the pFragView is visible , and the orientation is changed, it throws an exception much strange and not helping me to solve the mistake:
java.lang.RuntimeException: Unable to start activity ComponentInfo{minhaClasse}: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class fragment
...
Caused by: java.lang.IllegalStateException: Fragment 'minhaClasse' did not create a view.
And even worse, after debugging I found that onCreateView occurs and the view is created normally , although the error is shown before.
See if there are any errors in xml of that view.
– ramaral
XML is working this error has nothing to do!!! Since it works normally, it just doesn’t work in this specific situation.
– Rodrigo Santiago
Give a debug, because when you rotate the screen it will restart the whole Activity, see if there is something null in Activity or Fragment started, or some problem in the objects when inflating your Fragment, give a look also at this reply
– Furflez
it error when inflating , but if I already open in error Landscape not, enters normal
– Rodrigo Santiago