I’ve been reading some topics about filtering a list-view, but i am getting confused because i only got o few knowledge on adapters and different kinds of it. i found a solution thats is almost similar to my problem. Here is the code posted by Zoleas
TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
_myAdapter.getFilter().filter(s);
}
};
_filterText = (EditText) findViewById(R.id.search_box);
_filterText.addTextChangedListener(filterTextWatcher);
I am confused on how i can declare my adapter in the method Ontextchanged because my adapter looks like this.
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, result));
Need help on how to implement the filter here is my full code on my listview.
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.firstaid);
filterText = (EditText) findViewById(R.id.acET);
DbHelper tblFa = new DbHelper(this);
tblFa.open();
ArrayList<String> result = tblFa.getFAData();
result = tblFa.getFAData();
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, result));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
tblFa.close();
}
try that;