【发布时间】:2015-02-04 22:51:16
【问题描述】:
我必须在具有 Alphabetical SectionHeader 的 ListView 中实现 Filter .ListView having Alphabetic Section Header
我使用上面链接中的示例来创建我的 ListView。如何在此 ListView 中实现搜索过滤器。我需要一个像下面这样的布局
【问题讨论】:
标签: android android-listview filter
我必须在具有 Alphabetical SectionHeader 的 ListView 中实现 Filter .ListView having Alphabetic Section Header
我使用上面链接中的示例来创建我的 ListView。如何在此 ListView 中实现搜索过滤器。我需要一个像下面这样的布局
【问题讨论】:
标签: android android-listview filter
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);
}
}
【讨论】: