Search code examples
androidandroid-fragmentsgoogle-cloud-firestorefirebaseui

FirestoreRecycleview not load data after Switch menu in Bottom Navbar


I made FirestoreRecycleview in home-menu, when run app FirestoreRecycler work properly but when I open other Menu in Bottom Navbar, FirestoreReclyclerview not Load data

for Example :

  • I Have Bottom Navbar with 2 Fragment A and B
  • In Fragment A, I Have A RecycleView with Adapter From FirestoreRecyclerAdapter
  • when I open Fragment B and open Fragment A again, fragment A doesn't show Data in recyclerview

This is When run app in First Time :

This is when I run app in First time

This is After I Click other navbar button and open this fragment again :

This is after I Choose other Navbar menu

this is my code that I call in onCreate()

 private void setkelaslist() {
        Query query = fdb.collection("kelas").whereEqualTo("email",email_txt);
        FirestoreRecyclerOptions<kelas_profil> options = new FirestoreRecyclerOptions.Builder<kelas_profil>().
                setQuery(query,kelas_profil.class)
                .build();
        adapter = new listkelasadapter(options,this);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter.startListening();
        adapter.notifyDataSetChanged();
        recyclerView.setAdapter(adapter);
    }

Another request: one more question, I delete items with a button click, it is deleted but when I create a new item with same data, in Toast it says Complete but it doesn't add data.


Solution

  • You forgot adding start listening method for your adapters. @Override protected void onStart() { super.onStart(); adapter.startListening(); }