I have a listview where it receives the data via Firebase. But if it is empty and not a white screen in the Activity where it is, I put a background image similar to the example below.
Thisismycodewhereyouareplacingtheimage.Itdoesatestifthesizeofthelistviewisequalto0,itdisplaysanImageView,otherwisethedata.
if(listOnibusAtrasado.size()==0){progressBar.setVisibility(View.INVISIBLE);arrayAdapterOnibusAtrasado.notifyDataSetChanged();listView_OnibusAtrasado.setAdapter(arrayAdapterOnibusAtrasado);imagem.setImageResource(R.drawable.ic_smile);txt_NenhumHorarioRelatado.setText("Nenhum Atraso Relatado pelos Usuários");
}else {
arrayAdapterOnibusAtrasado.sort(new Comparator<OnibusAtrasados>() {
@Override
public int compare(OnibusAtrasados o1, OnibusAtrasados o2) {
return o2.getHorário().compareTo(o1.getHorário());
}
});
arrayAdapterOnibusAtrasado.sort(new Comparator<OnibusAtrasados>() {
@Override
public int compare(OnibusAtrasados o1, OnibusAtrasados o2) {
return o2.getData().compareTo(o1.getData());
}
});
arrayAdapterOnibusAtrasado.notifyDataSetChanged();
listView_OnibusAtrasado.setAdapter(arrayAdapterOnibusAtrasado);
progressBar.setVisibility(View.INVISIBLE);
}
My question is, would that be the right way? For what I am doing is to take an image and a textview and put in that test (if else) that I quoted above.