Search shows result after I remove Text from EditText

Viewed 47

I am trying to fetch data from firestore. When I type in the editText the RecyclerView doesn't show results. but when I remove the text from

@Override
public boolean onQueryTextChange(String newText) {

  mStore.collection("Featured").whereGreaterThanOrEqualTo("name", newText).get().addOnCompleteListener(new OnCompleteListener < QuerySnapshot > () {@Override
    public void onComplete(@NonNull Task < QuerySnapshot > task) {
      if (task.isSuccessful()) {
        for (DocumentSnapshot doc: task.getResult().getDocuments()) {
          Items f1 = doc.toObject(Items.class);
          mItemList.add(f1);
          mAdapter.notifyDataSetChanged();
          Log.d("SearchItem", f1.getName());
        }
      }
    }
  });
  return true;
}
1 Answers

I got the solution. I just have to convert the string into lower case with toLowerCase(Locale.ENGLISH). Locale is helpful when we are doing case operations and URL related tasks. You can learn more about locale from https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html .

mItemList.clear();
                mStore.collection("Featured").orderBy("name").whereLessThanOrEqualTo("name", newText.toLowerCase(Locale.ENGLISH)).get()
                        .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                            @Override
                            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                if(task.isSuccessful()) {
                                    for(DocumentSnapshot doc:task.getResult().getDocuments()) {
                                        Items f1 = doc.toObject(Items.class);
                                        mItemList.add(f1);
                                        Log.d("SearchItem", f1.getName());
                                    }
                                    mAdapter.notifyDataSetChanged();
                                }
                            }
                        });
Related