0

I made a dictionary app but I search a word for example water,water does not show first line.I want to filter water or w suggestion word.Whats wrong my code? Thnks

   @Override
        public boolean onQueryTextChange(String newText) {


            newText = newText.toLowerCase();

            final ArrayList<DictObjectModel> filteredList = new ArrayList<DictObjectModel>();

            for (int i = 0; i < wordcombimelist.size(); i++) {

                final String text = wordcombimelist.get(i).toLowerCase();
                if (text.contains(newText) && (text.equals(newText)) ) {

                   filteredList.add(new DictObjectModel(wordcombimelist.get(i),meancombimelist.get(i)));
                }



            }
            adapter = new CustomAdapter(filteredList);
            recyclerView.setAdapter(adapter);


            return true;
        }
K.Gangster
  • 35
  • 1
  • 8

1 Answers1

0

First of all you shouldn't be creating new Adapter each time you want to filter your list. You should implement add and remove methods in your CustomAdapter.

Here you can find instruction about filtering the RecyclerView.

Community
  • 1
  • 1
ostojan
  • 608
  • 1
  • 7
  • 17
  • It's not neccesary add or remove methods.I use sqlite database and embedeed the app my database.But filter does not work.I want to list when user press "a" key then list a... words – K.Gangster Apr 12 '17 at 09:42
  • Like I wrote earlier. You should not create new Adapter each time you want to change the content of your RecyclerView. In CustomAdapter create method called "filter" or something like that which takes List of your DictObjectModel, remove from list in CustomAdapter unnessescary items and call notifyDataSetChanged inside "filter" method. – ostojan Apr 12 '17 at 09:51
  • Ok thnx I try to your suggestion:) – K.Gangster Apr 12 '17 at 09:56
  • I try your suggestion but answer is very simple)I search google and find this code startWith ;)if (text.toLowerCase.startWith(newText.toLowerCase) – K.Gangster Apr 12 '17 at 12:17
  • Well you're right. I didn't notice that your statement have wrong conditions. But still, I encourage you to extend your Adapter class instead of creating new after each filter run. – ostojan Apr 12 '17 at 12:34
  • This is simple tricks) But you are right I must to extend my Adapter class.Thnx) – K.Gangster Apr 12 '17 at 12:50