Skip to content

Instantly share code, notes, and snippets.

@ns-github14
Created December 5, 2020 07:49
Show Gist options
  • Save ns-github14/a9e74bc066ce743f8b162d20c2181ac1 to your computer and use it in GitHub Desktop.
Save ns-github14/a9e74bc066ce743f8b162d20c2181ac1 to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
RVAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
base = FirebaseFirestore.getInstance().collection("Doctors");
recyclerView = findViewById(R.id.rv);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
FirestoreRecyclerOptions<Doctor_Class> options = new FirestoreRecyclerOptions.Builder<Doctor_Class>().setQuery(base, Doctor_Class.class).build();
adapter = new RVAdapter(options);
recyclerView.setAdapter(adapter);
}
// Function to tell the app to start getting
// data from database on starting of the activity
@Override protected void onStart()
{
super.onStart();
adapter.startListening();
}
// Function to tell the app to stop getting
// data from database on stoping of the activity
@Override protected void onStop()
{
super.onStop();
adapter.stopListening();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment