title: Android RecyclerView with Filterable interface
body: <p>I'm trying to <code>implement</code> <code>RecyclerView</code> with <code>Filterable interface</code> in order to <code>Filter</code> my list from <code>Toolbar</code>'s <code>SearcView Widget</code>.</p>
  
  <p>But My Problem is that I <strong>can't Update my list with new Data.</strong> <code>notifyDataSetChanged()</code> in <code>publishResults</code> method does nothing, I don't know why.</p>
  
  <p><strong>Only the count of elements is changed.</strong></p>
  
  <p>Here is my implementation of <code>Recycler Adapter</code> with <code>Filterable Interface</code>:</p>
  
  <pre><code>public class RecyclerAdapter extends RecyclerView.Adapter&lt;RecyclerAdapter.ShoppingListHolder&gt; implements Filterable {
  
      private Context context;
      private ArrayList&lt;ShoppingListModel&gt; shoppingList, filteredShoppingList;
      private ListFilter listFilter;
  
      public RecyclerAdapter(Context context, ArrayList&lt;ShoppingListModel&gt; shoppingList) {
          this.context = context;
          this.shoppingList = shoppingList;
          this.filteredShoppingList = shoppingList;
      }
  
      @Override
      public ShoppingListHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
          View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.shopping_listitem_layout_new, viewGroup, false);
          return new ShoppingListHolder(itemView);
      }
  
      @Override
      public int getItemCount() {
          return this.filteredShoppingList.size();
      }
  
      @Override
      public void onBindViewHolder(ShoppingListHolder shoppingListHolder, int position) {
          final ShoppingListModel list = this.filteredShoppingList.get(position);
          shoppingListHolder.titleView.setText(list.getTitle());
  
          if(list.getAlarmDate() == null || list.getAlarmDate().isEmpty())
              shoppingListHolder.reminderView.setText("--/--/--");
          else
              shoppingListHolder.reminderView.setText(list.getAlarmDate());
  
          ArrayList&lt;ListItemModel&gt; listItems = DBManager.getShoppingListItems(DBHelper.SHOPPING_LIST_ITEM_PARENT_ID + " = " + list.getId());
          double maxItems = listItems.size();
          double checkedCount = 0;
          shoppingListHolder.itemContainer.removeAllViews();
          for (int i = 0; i &lt; listItems.size(); i++) {
              ListItemModel item = listItems.get(i);
              ShoppingListItemView listItem = new ShoppingListItemView(context, item, i + 1, list.getColor());
              shoppingListHolder.itemContainer.addView(listItem);
              if (item.isChecked() == ListItemModel.ListItemState.Checked.ordinal()) {
                  checkedCount++;
              }
          }
  
          if(checkedCount == 0){
              shoppingListHolder.progressPercentageView.setText("0%");
          }else{
              shoppingListHolder.progressPercentageView.setText((int)(checkedCount / maxItems * 100) + "%");
          }
  
          shoppingListHolder.progressBar.setMax((int) maxItems);
          shoppingListHolder.progressBar.setProgress((int) checkedCount);
  
          shoppingListHolder.rippleView.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
              @Override
              public void onComplete(RippleView rippleView) {
                  Intent shoppingList = new Intent(context, ShoppingListItemActivity.class);
                  Bundle extras = new Bundle();
                  extras.putLong(ShoppingListModel.SHOPPING_LIST_MODEL_KEY, list.getId());
                  shoppingList.putExtras(extras);
                  if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
                      context.startActivity(shoppingList, ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context).toBundle());
                  }else{
                      context.startActivity(shoppingList);
                  }
              }
          });
      }
  
      class ShoppingListHolder extends RecyclerView.ViewHolder {
          CardView cardView;
          RippleView rippleView;
          TextView titleView;
          TextView reminderView;
          ImageView locationPin;
          LinearLayout itemContainer;
          TextView progressPercentageView;
          ProgressBar progressBar;
  
          public ShoppingListHolder(View itemView) {
              super(itemView);
              rippleView = (RippleView) itemView.findViewById(R.id.card_view_ripple);
              cardView = (CardView) itemView.findViewById(R.id.card_view);
              titleView = (TextView) itemView.findViewById(R.id.title);
              reminderView = (TextView) itemView.findViewById(R.id.reminder);
              locationPin = (ImageView) itemView.findViewById(R.id.location_pin);
              itemContainer = (LinearLayout) itemView.findViewById(R.id.item_container);
              progressPercentageView = (TextView) itemView.findViewById(R.id.progress_percentage_label);
              progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
          }
      }
  
      @Override
      public Filter getFilter() {
          if (listFilter == null) {
              listFilter = new ListFilter();
          }
          return listFilter;
      }
  
      private class ListFilter extends Filter {
  
          @Override
          protected FilterResults performFiltering(CharSequence constraint) {
              FilterResults filterResults = new FilterResults();
              ArrayList&lt;ShoppingListModel&gt; tempList;
              if (constraint != null &amp;&amp; constraint.length() &gt; 0) {
  
                  tempList = DBManager.getShoppingList(DBHelper.SHOPPING_LIST_TITLE + " like '%" + constraint + "%' or " +
                                                      DBHelper.SHOPPING_LIST_TAGS + " like '%" + constraint + "%'");
  
                  filterResults.count = tempList.size();
                  filterResults.values = tempList;
              } else {
                  tempList = DBManager.getShoppingList(null);
                  filterResults.count = tempList.size();
                  filterResults.values = tempList;
              }
              return filterResults;
          }
  
          @Override
          protected void publishResults(CharSequence constraint, FilterResults results) {
              filteredShoppingList.clear();
              filteredShoppingList.addAll((ArrayList&lt;ShoppingListModel&gt;) results.values);
              notifyDataSetChanged();
          }
      }
  }
  </code></pre>
  
  <p>Thanks people for help in advance.</p>