title: Update Recyclerview List After Deleting Row
body: <p>I have tried most answers from this site without getting the desired result.</p>
  
  <p>I have recyclerview with a list of items and a button contained in each row. When the button is clicked, I want the entire row to be deleted and list updated automatically.</p>
  
  <p>Here's my adapter class code:</p>
  
  <pre><code>public class CartAdapter extends RecyclerView.Adapter&lt;CartViewHolder&gt; {
  
  private static final String TAG = CartAdapter.class.getSimpleName();
  
  private final Context context;
  private List&lt;Cart&gt; itemsList;
  private String id;
  
  public CartAdapter(Context context, List&lt;Cart&gt; itemsList) {
      this.context = context;
      this.itemsList = itemsList;
  }
  
  @Override
  public CartViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cart_items_layout, parent, false);
      return new CartViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(final CartViewHolder viewholder, final int position) {
      final Cart cart = itemsList.get(position);
      id = cart.getProductId();
  
      AndroidNetworking.get(Constants.PRODUCT_DETAILS_ENDPOINT + id)
              .setTag("Get Product Image")
              .setPriority(Priority.HIGH)
              .build()
              .getAsJSONObject(new JSONObjectRequestListener() {
                  @Override
                  public void onResponse(JSONObject response) {
                      Log.d(TAG, "Cart Item Image Response:\t" + response.toString());
                      String imagePath = null;
                      try {
                          JSONObject itemObject = new JSONObject(response.toString());
                          JSONObject data = itemObject.getJSONObject("data");
                          imagePath = data.getString("image");
  
                          Picasso.with(context)
                                  .load(imagePath)
                                  .placeholder(R.drawable.noimage)
                                  .into(viewholder.cartItemImg);
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
  
                  @Override
                  public void onError(ANError anError) {
  
                  }
              });
  
      viewholder.cartItemTitle.setText(cart.getProductTitle());
      viewholder.cartQtyTV.setText(cart.getCartQty() + "");
      viewholder.clearProductIV.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              removeProductRow(cart);
          }
      });
      viewholder.decreaseCartIV.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              decreaseProduct();
          }
      });
      viewholder.increaseCartIV.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              increaseProduct();
          }
      });
  }
  
  private void increaseProduct() {
  
  }
  
  private void decreaseProduct() {
  
  }
  
  public void removeProductRow(final Cart cart) {
      AndroidNetworking.get(Constants.REMOVE_PRODUCT_CART + id)
              .setTag("Delete Product From Cart")
              .setPriority(Priority.HIGH)
              .build()
              .getAsJSONObject(new JSONObjectRequestListener() {
                  @Override
                  public void onResponse(JSONObject response) {
                      Log.d(TAG, "Delete Product From Cart Response:\t" + response.toString());
  
                      int position = itemsList.indexOf(cart);
                      itemsList.remove(position);
                      notifyItemRemoved(position);
                      notifyItemRangeChanged(position, itemsList.size());
                  }
  
                  @Override
                  public void onError(ANError anError) {
  
                  }
              });
  }
  
  @Override
  public int getItemCount() {
      if (itemsList == null) {
          return 0;
      }
      return itemsList.size();
  }
  }
  </code></pre>
  
  <p>This code works and the item is deleted. However, the list does not update until I re-visit the activity again. How can I update the view immediately?</p>