【问题标题】:How to implement searchFilter in ListView having Alphabet-indexed Section Headers如何在具有字母索引的节标题的 ListView 中实现 searchFilter
【发布时间】:2015-02-04 22:51:16
【问题描述】:

我必须在具有 Alphabetical SectionHeader 的 ListView 中实现 Filter .ListView having Alphabetic Section Header

我使用上面链接中的示例来创建我的 ListView。如何在此 ListView 中实现搜索过滤器。我需要一个像下面这样的布局

【问题讨论】:

    标签: android android-listview filter


    【解决方案1】:
    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);
        }
       }
    

    【讨论】:

    • 我使用了 curosr 适配器
    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    相关资源
    最近更新 更多