I'm setting the setEmptyView method in my listview, but when it is empty it does not show the desired view, and it also does not give any error in the log.
public class ListaNotificacoes extends Fragment{
View minha_view;
private ListView lista_notify;
private ImageView botao_deletar;
private ItensDoAdaptador itens_adapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
minha_view = inflater.inflate(R.layout.lista_notificacoes, container, false);
return minha_view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
recupera_tarefa();
}
public void recupera_tarefa(){
try {
Cursor cursor = banco_dados.rawQuery("SELECT * FROM lista_notificacoes order by id DESC", null);
//recupera os ids da coluna
int indiceColunaId = cursor.getColumnIndex("id");
int indiceColunaTexto = cursor.getColumnIndex("texto_notificacao");
int indiceColunaHora = cursor.getColumnIndex("hora_notificacao");
final ArrayList<ItensDaLista> lista_menu = new ArrayList<>();
itens_adapter = new ItensDoAdaptador(getActivity(), lista_menu);
lista_notify = (ListView)getActivity().findViewById(R.id.list_notify);
lista_notify.setAdapter(itens_adapter);
lista_notify.setEmptyView(getActivity().getLayoutInflater().inflate(R.layout.empty_listview, null));
//listar as notificações
cursor.moveToFirst();
while (cursor != null) {
String teste = cursor.getString(indiceColunaId);
lista_menu.add(new ItensDaLista(teste.toString(),cursor.getString(indiceColunaTexto),cursor.getString(indiceColunaHora),R.drawable.delete));
cursor.moveToNext();
}
}catch (Exception e){
e.printStackTrace();
}
}
}