0

enter code hereIm creating a blood donation app that enables users to find donors with specific blood group and district.. app

I've completed saving the donors information part in firebase real time database.. firebase database

can anyone help me to retrieve users with specific blood group and district

i tried by this code.. but not working

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    usersList = new ArrayList<>();
    adapter = new UsersAdapter(this, usersList);
    recyclerView.setAdapter(adapter);dbusers = 
    FirebaseDatabase.getInstance().getReference("users");
    Query query3 = FirebaseDatabase.getInstance().getReference("users")
            .orderByChild("district")
            .equalTo("kannur");


    query3.addListenerForSingleValueEvent(valueEventListener);
}


    ValueEventListener valueEventListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                usersList.clear();
                if (dataSnapshot.exists()) {
                    for (DataSnapshot snapshot : dataSnapshot.getChildren()) 
                      {
                        Users user = snapshot.getValue(Users.class);
                        usersList.add(user);
                    }
                    adapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        };
Jazeem Pm
  • 1
  • 1
  • Using FirebaseDatabase query, you can, directly from the database, retrieve records with only one query value if you use orderByChild. In otherwords, you can use either orderByChild("group") or orderByChild("district") but not both. You can decide to use one of the query parameters e.g "district" on the FirebaseQuery and then filter the records retrieved by through your iteration code before data is presented to the UI – orimdominic Aug 15 '18 at 11:19
  • save all users id in user node along with there blood group and get data from that node – Tara Aug 15 '18 at 11:19
  • Please check the duplicate to see how you can solve this using a combined property. – Alex Mamo Aug 15 '18 at 11:21

0 Answers0