Estou tentando rotacionar, se exibir apenas dá certo, mas ao rotacionar a tela de um tablet com dois fragmentos dá pau:
São apresentadas as seguintes mensagens de erro:
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.alura.estudo/br.com.alura.estudo.fragmentActivity.ProvaActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
Caused by: java.lang.IllegalStateException: Fragment br.com.alura.estudo.fragment.ProvaListaFragment did not create a view.
Activity :
package br.com.alura.estudo.fragmentActivity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import br.com.alura.estudo.R;
import br.com.alura.estudo.fragment.ProvaListaFragment;
/**
* Created by Fernando on 15/04/2016.
*/
public class ProvaActivity extends FragmentActivity {
// Log.v("ORIENTATION_PORTRAIT :", String.valueOf(Configuration.ORIENTATION_PORTRAIT));
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.provas);
preecheLayoutConformeTela();
}
private void preecheLayoutConformeTela() {
FragmentTransaction tx = getFragmentManager().beginTransaction();
tx.replace(R.id.provas_detalhe2, new ProvaListaFragment());
tx.replace(R.id.provas_detalhe, new ProvaListaFragment());
tx.commit();
}
// private boolean layoutParaTablet() {
// return getResources().getBoolean(R.bool.isTablet);
// }
}
Classe do Fragment :
package br.com.alura.estudo.fragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import br.com.alura.estudo.R;
import br.com.alura.estudo.modelo.Prova;
/**
* Created by Fernando on 15/04/2016.
*/
public class ProvaListaFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.lista_provas_view, container, false);
ListView listaProvas = (ListView) view.findViewById(R.id.lista_provas);
List<String> listaCobol = new ArrayList<String>();
listaCobol.add("Sintaxe");
listaCobol.add("Lógica");
listaCobol.add("Conceitos");
listaCobol.add("Le-Grava");
List<String> listaNatural = new ArrayList<String>();
listaNatural.add("Sintaxe");
listaNatural.add("Lógica");
listaNatural.add("Conceitos");
listaNatural.add("Le-Grava");
Prova p1 = new Prova("14/04/2016", "COBOL", "Prova de Cobol", listaCobol);
Prova p2 = new Prova("16/04/2016", "Natural", "Prova de Natural", listaNatural);
List<Prova> provas = Arrays.asList(p1, p2);
final ArrayAdapter<Prova> adapter = new ArrayAdapter<Prova>(getActivity(), android.R.layout.simple_list_item_1, provas);
listaProvas.setAdapter(adapter);
return view;
}
}
Xml que contem os dois fragments:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="br.com.alura.estudo.fragment.ProvaListaFragment"
android:id="@+id/provas_detalhe2"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment class="br.com.alura.estudo.fragment.ProvaListaFragment"
android:id="@+id/provas_detalhe"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"/>
</LinearLayout>
O fragment (dupliquei o mesmo para facilita):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lista_provas"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Alguém passou por isso?