Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

java - Search shows result after I remove Text from EditText

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;
}
question from:https://stackoverflow.com/questions/65868641/search-shows-result-after-i-remove-text-from-edittext

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
                                }
                            }
                        });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...