Try this:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Verificar se ha dados ou nao
boolean isEmpty = false;
View view = null;
if( isEmpty ){
view = inflater.inflate(R.layout.fragment_noa_cidadao2, container, false);
}else{
view = inflater.inflate(R.layout.fragment_outra, container, false);
}
return view;
}
EDIT
Another way is to bring the contents of the two into a single layout
and show according to the quantity of items:
Example:
Layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<!-- SETADO A VISIBILIDADE PARA GONE -->
<LinearLayout
android:id="@+id/listaVazia"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
<ListView
android:id="@+id/listaItens"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
Java
private LinearLayout listaVazia;
private ListView listaItens;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
* Inicializamos todos os componentes!
**/
listaItens = ListView.class.cast(findViewById(R.id.lista));
listaVazia = LinearLayout.class.cast(findViewById(R.id.lisyVazia));
}
@Override
protected void onStart() {
super.onStart();
// Aqui você deverá saber se existem itens para ser exibidos!
if(isEmpty){
// Se está vazia, vamos esconder a lista de Itens e exibir Lista Vazia!
listaItens.setVisibility(View.GONE);
listaVazia.setVisibility(View.VISIBLE);
}else {
listaItens.setVisibility(View.VISIBLE);
listaVazia.setVisibility(View.GONE);
}
}