title: How to delete on swipe an item from Filtered list? [RecyclerView]
body: <p>I'm having an issue while trying to delete an item from a RecyclerView after i've searched for it by using SearchView, while if i don't use the SearchView and delete the item normally it's works fine.</p>
  
  <p>Here is an example where i'm deleting the item and where i'm searching for 2 deleting it and it still remain in the list.</p>
  
  <p><a href="https://i.stack.imgur.com/go9a0.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/go9a0.gif" alt="enter image description here"></a></p>
  
  <p>While here is the method where i'm deleting the item on swipe in my Activity</p>
  
  <pre><code>  new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
          @Override
          public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
              return false;
          }
  
          @Override
          public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
  
              if (direction == ItemTouchHelper.RIGHT) {
                  itemAdapter.removeItem( viewHolder.getAdapterPosition());
              }
  
              if (direction == ItemTouchHelper.LEFT) {
                  itemAdapter.removeItem( viewHolder.getAdapterPosition());
              }
  
          }
      }).attachToRecyclerView(recyclerView);
  
  }
  </code></pre>
  
  <p>While here is code from my Adapter</p>
  
  <pre><code>public class ItemAdapter extends RecyclerView.Adapter&lt;ItemAdapter.ExampleViewHolder&gt;  implements Filterable {
  
  
      private ArrayList&lt;ItemModel&gt; variantiConstructors;
      private ArrayList&lt;ItemModel&gt; mFilteredList;
      private OnItemClickListener mListener;
  
      public interface  OnItemClickListener{
          void onItemClick(int position);
      }
  
      public void setOnItemClickListener(OnItemClickListener listener){
          mListener = listener;
      }
  
      @NonNull
      @Override
      public ItemAdapter.ExampleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler,parent,false);
          RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
          v.setLayoutParams(lp);
          return new ItemAdapter.ExampleViewHolder(v, mListener);
      }
  
      ItemAdapter(ArrayList&lt;ItemModel&gt; exampleList){
          variantiConstructors = exampleList;
          mFilteredList = variantiConstructors;
      }
  
      @Override
      public void onBindViewHolder(@NonNull final ItemAdapter.ExampleViewHolder holder, @SuppressLint("RecyclerView") final int position) {
          ItemModel item = variantiConstructors.get(position);
  
          holder.desc.setText(item.getCodiceArticolo());
          holder.qta.setText(item.getQta());
  
          holder.qta.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
              }
  
              @Override
              public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                  variantiConstructors.get(position).setQta(holder.qta.getText().toString());
              }
  
              @Override
              public void afterTextChanged(Editable editable) {
              }
          });
  
  
          if(position % 2 == 0 ){
              holder.itemView.setBackgroundColor(Color.parseColor("#5C5C5C"));
  
          }else if(position % 2 == 1){
              holder.itemView.setBackgroundColor(Color.parseColor("#9E9E9E"));
          }
      }
  
  
      @Override
      public Filter getFilter() {
          return new Filter() {
              @Override
              protected FilterResults performFiltering(CharSequence constraint) {
                  final FilterResults oReturn = new FilterResults();
                  final ArrayList&lt;ItemModel&gt; results = new ArrayList&lt;&gt;();
                  if (mFilteredList == null)
                      mFilteredList = new ArrayList&lt;&gt;(variantiConstructors);
                  if (constraint != null &amp;&amp; constraint.length() &gt; 0) {
                      if (mFilteredList != null &amp;&amp; mFilteredList.size() &gt; 0) {
                          for (final ItemModel cd : mFilteredList) {
                              if (cd.getCodiceArticolo().toLowerCase()
                                      .contains(constraint.toString().toLowerCase()))
                                  results.add(cd);
                          }
                      }
                      oReturn.values = results;
                      oReturn.count = results.size(); //newly Aded by ZA
                  } else {
                      oReturn.values = mFilteredList;
                      oReturn.count = mFilteredList.size(); //newly added by ZA
                  }
                  return oReturn;
              }
  
              @SuppressWarnings("unchecked")
              @Override
              protected void publishResults(final CharSequence constraint,
                                            FilterResults results) {
                  variantiConstructors = new ArrayList&lt;&gt;((ArrayList&lt;ItemModel&gt;) results.values);
                  notifyDataSetChanged();
              }
          };
      }
  
      @Override
      public int getItemCount() {
          return variantiConstructors.size();
      }
  
      public class ExampleViewHolder extends RecyclerView.ViewHolder {
  
          public TextView desc;
          public EditText qta;
  
          ExampleViewHolder(View itemView, final OnItemClickListener listener) {
              super(itemView);
  
              desc = itemView.findViewById(R.id.Desc);
              qta = itemView.findViewById(R.id.Qta);
  
  
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      if(listener != null){
                          int position = getAdapterPosition();
                          if(position != RecyclerView.NO_POSITION){
                              listener.onItemClick(position);
                          }
                      }
                  }
              });
  
  
          }
      }
  
      public ArrayList&lt;ItemModel&gt; getList(){
          return variantiConstructors;
      }
  
      public void removeItem(int position) {
          variantiConstructors.remove(position);
          notifyDataSetChanged();
      }
  }
  </code></pre>