使用 BaseExpandableListAdapter 过滤 ExpandableListView 中的文本
我需要你的帮助:) 我有一个 EditText,下面有一个 ExpandableListView。我已将 BaseExpandableListAdapter 与 groups/child 一起使用。我希望当用户在 EditText 中写入时,ExpandableListView 仅显示插入文本的组(项目)。 我认为我必须创建一个过滤器。 这是我的一段源代码。有人可以帮助我吗?先感谢您
@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 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 {
......
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了它,我以这种方式实现了 Filterable 接口:
然后我重写了 getfilter() 方法。最后,我编写了一个扩展 Filter 类的类。
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.