I need your help 🙂
I have a EditText and below a ExpandableListView. I have used a BaseExpandableListAdapter with groups/child. I would like that when the user writes in the EditText the ExpandableListView shows only the group (item) with the text inserted.
I think that I have to create a filter.
Here there is a piece of my source code.Could anyone help me? Thank you in advance
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState
setContentView(R.layout.main);
et = (EditText) findViewById(R.id.filterText);
et.setSingleLine();
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if (et.getText().toString().equals(""))
elv.setBackgroundColor(Color.BLACK);
else
{
elv.setBackgroundColor(Color.WHITE);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
elv=getExpandableListView();
mAdapter = new MyExpandableListAdapter(fields_select,description);
elv.setAdapter(mAdapter);
class MyExpandableListAdapter extends BaseExpandableListAdapter {
......
}
I solved it, I have implemented the interface Filterable in this way:
and then I have override the getfilter() method. In the end, I wrote a class that extends the Filter class.