我必须在ListView中使用Alphabetical SectionHeader实现Filter。ListView having Alphabetic Section Header
我使用上面链接中的示例来创建我的ListView。如何在此ListView中实现搜索过滤器。我需要一个类似下面
的布局答案 0 :(得分:0)
For this to implement you need a TextWatcher for the edittext in which user will type when user will type something you create a Arraylist that will be updated with the items and then notify the Listview
search.addTextChangedListener(new TextWatcher() {
Boolean called =false;
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
coffeeshopsearch=new ArrayList<CoffeeShopBean>();
for (int i = 0; i < coffeeShop.size(); i++) {
if(coffeeShop.get(i).name1.toLowerCase().contains(String.valueOf(s).toLowerCase()))
{
coffeeshopsearch.add(coffeeShop.get(i));
}
}
if(coffeeshopsearch.size()>0)
{
lv.setVisibility(View.VISIBLE);
adapter.add(coffeeshopsearch);
adapter.notifyDataSetChanged();
}
else
{
if(!called)
{
Toast.makeText(getActivity(), "No Items Found!!!!", Toast.LENGTH_SHORT).show();
called=true;
}
lv.setVisibility(View.GONE);
}
}