从编辑文本过滤列表视图 [英] Filter list view from edit text
问题描述
我有一个编辑文字作为搜索栏和列表视图用于筛选我输入但不幸的是,它并不过滤列表视图中的文本。我已经使用了自定义数组适配器对象朋友。 朋友对象的姓名,地址和电话号码,但我只是想过滤它的名字。在我的活动......
I have an edit text as a search bar and a list view that filters the text that I typed but unfortunately, it doesn't filter the list view. I have used an customize array adapter with object Friend. Friend object has name, address and phone number but I only want to filter its name. In my activity...
searchBarTextView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
friendListAdapter.getFilter().filter(s);
}}
而在适配器...
While in adapter...
@Override
public Filter getFilter() {
Log.d(TAG, "begin getFilter");
if(newFilter == null) {
newFilter = new Filter() {
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
// TODO Auto-generated method stub
Log.d(TAG, "publishResults");
notifyDataSetChanged();
}
可能有人请帮助我如何正确显示滤波阵列适配器?我觉得notifyDataSetChanged不会被调用。谢谢你。
Could someone please help me how to correctly show the filtered array adapter? I think the notifyDataSetChanged is not invoked. Thanks.
推荐答案
我的问题是解决了,发现我要重写 getCount将()和的getItem()
My problem is solved, found out that I have to override getCount() and getItem().
这篇关于从编辑文本过滤列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!