Why my search functionality is not working in firebase firestore in android

Viewed 50

I am working on an application in android where I have a list of products in my recyclerview fetching from firebase firestore it is like Olx now I want to implement search functionality in my application. how can I achieve that? Please guide me I am new to android and I have no idea about it. how can I implement a search option like OLX to find my products? I have tried some tutorials but did not get them.

CODE OF SEARCHBAR

  searchbar.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
       @Override
       public boolean onQueryTextSubmit(String query) {

           searchData(query);
           return false;
       }

       @Override
       public boolean onQueryTextChange(String newText) {
           return false;
       }
   });

CODE OF SEARCH METHOD

  public void searchData(String searchText) {
    
    //PROGRESS DIALOGUE
    pd.setTitle("Searching");
    pd.show();

    firebaseFirestore.collectionGroup("room_details").whereEqualTo("search", searchText.toLowerCase()).get()
            .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

                    roomsDetails.clear();

                    pd.dismiss();
                    List<DocumentSnapshot> list = queryDocumentSnapshots.getDocuments();
                    for (DocumentSnapshot d : list) {
                        RoomsDetails obj = d.toObject(RoomsDetails.class);
                        roomsDetails.add(obj);
                    }
                    roomsAdapter.notifyDataSetChanged();
                }
            }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {


        }
    });
}

enter image description here enter image description here

0 Answers
Related