title: How to remove item in recyclerview in android
body: <p>i am doing simple cart application. which will show cart details in recycler view.
  Here i am going to decrease the quantity value upto 1.The item going to be remove from item adapter.it will be working fine.But when i was going to decrease the second item quantity value,it will remove without checking the condition. My condition is if the quantity is below 1 the item going to remove. </p>
  
  <p>ItemAdapter.java</p>
  
  <pre><code>public class ItemAdapter extends RecyclerView.Adapter&lt;ItemAdapter.ViewHolder&gt; {
      Context context;
      ArrayList&lt;ItemData&gt; itemDataList;
      int quantity,t_amount;
      totalAmount totalAmount;
  
      public ItemAdapter(Context context, ArrayList&lt;ItemData&gt; itemDataList) {
          this.context = context;
          this.itemDataList = itemDataList;
          totalAmount = (ItemAdapter.totalAmount) context;
  
      }
  
      @NonNull
      @Override
      public ItemAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_details,parent,false);
          return new ViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(@NonNull final ViewHolder holder, final int pos) {
          ItemData itemData = itemDataList.get(pos);
          holder.txtPrice.setText(itemData.getPrice());
          holder.txtDesc.setText(itemData.getDescription());
          holder.txtCartCount.setText(itemData.getCartCount());
          holder.btnCartDec.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  if(quantity &lt;= 1){
                      itemDataList.remove(holder.getAdapterPosition());
                      notifyItemRemoved(holder.getAdapterPosition());
                      notifyItemRangeChanged(holder.getAdapterPosition(),itemDataList.size());
                  }else {
                      quantity = Integer.parseInt(itemDataList.get(pos).getCartCount());
                      quantity = quantity-1;
                      itemDataList.get(pos).setCartCount(String.valueOf(quantity));
                      notifyDataSetChanged();
                      holder.txtCartCount.setText(String.valueOf(quantity));
                  }
  
              }
          });
          holder.btnCartInc.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  quantity = Integer.parseInt(itemDataList.get(pos).getCartCount());
                  quantity = quantity+1;
                  itemDataList.get(pos).setCartCount(String.valueOf(quantity));
                  notifyDataSetChanged();
                  holder.txtCartCount.setText(String.valueOf(quantity));
  
              }
          });
      }
  
      @Override
      public int getItemCount() {
          return itemDataList.size();
      }
  
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          TextView txtPrice, txtDesc, txtCartCount, btnCartDec, btnCartInc;
  
          public ViewHolder(@NonNull View itemView) {
              super(itemView);
              txtPrice = itemView.findViewById(R.id.itemView_price);
              txtDesc = itemView.findViewById(R.id.itemView_desc);
              txtCartCount = itemView.findViewById(R.id.itemView_Count);
              btnCartDec = itemView.findViewById(R.id.itemViewDec);
              btnCartInc = itemView.findViewById(R.id.itemViewInc);
          }
      }
      public interface totalAmount{
          void t_amount(int amount);
      }
  
  }
  </code></pre>