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