0

I have a ListView from json file that is in my assets folder. The listView works perfectly, but I want to add Search to it. I want to add editText before the listView, and when the user types some text, the list will be filtered. I'm using SimpleAdapter for the listView. I've tried some tutorials but they don't work, or when I type in the editText textBox the items of the list are duplicated. Sorry for my bad English.

this is the code:

ListAdapter adapter = new SimpleAdapter(this, herbList,
             R.layout.caevi_list_item, new String[] { HERB_ID, HERB_NAME, HERB_DISCRIPTION}, 
                    new int[] { R.id.idbilka, R.id.name, R.id.discription});


 setListAdapter(adapter);



inputSearch = (EditText) findViewById(R.id.inputSearch);
inputSearch.setSingleLine();

inputSearch.addTextChangedListener(new TextWatcher() {

      @Override
      public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {

            ((Filterable) Caevi.this.adapter).getFilter().filter(cs);   

      }

      @Override
      public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {
         // TODO Auto-generated method stub

      }

      @Override
      public void afterTextChanged(Editable arg0) {
          // TODO Auto-generated method stub                          
      }

});

natt1708
  • 21
  • 1
  • 5
  • Post some code you have so far and specify what "doesn't work". – Simas Jan 10 '15 at 22:16
  • Use filter. This is the solution of your problem http://stackoverflow.com/questions/8255322/no-results-with-custom-arrayadapter-filter/8258457#8258457 and http://stackoverflow.com/questions/14118309/how-to-use-search-functionality-in-custom-list-view-in-android/14119383#14119383 – Rohit5k2 Jan 10 '15 at 22:17
  • Please try to implement this and if you face any issue post a question with details and we ll be happy to help. – Rohit5k2 Jan 10 '15 at 22:19

0 Answers0