0
I have a listview where he gets the data via Firebase. But if it is empty and not to leave a white screen in the Activity where it is, I put a background image like the example below.
That’s my code where you’re putting the image. It makes a test if the listview size is equal to 0, it displays an Imageview, otherwise the data.
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 ? Because what I’m doing is taking an image and a textview and putting in this test (if Else) that I quoted above.