title: How to delete item from ArrayList in Android
body: <p>In my application, I have 2 <code>recyclerview</code> into one activity. <br>
  I want when to add items in one <code>recyclerview', add this item into other</code>recyclerview`.<br></p>
  
  <p>In 2 <code>recyclerViews</code> for send data to activity I use <code>Interface</code>.<br></p>
  
  <p>But when click on items in <code>recyclerview</code> two show me error in <strong>Logcat</strong>.<br></p>
  
  <p><strong>Activity codes:</strong></p>
  
  <pre><code>public class SuggestFilmActivity extends AppCompatActivity implements SuggestedListener, SuggestedDeleteListener {
  
      @BindView(R.id.toolbarTitleTxt)
      TextView toolbarTitleTxt;
      @BindView(R.id.suggestFilm_searchEditText)
      EditText suggestFilm_searchEditText;
      @BindView(R.id.suggestFilm_searchBtn)
      ImageView suggestFilm_searchBtn;
      @BindView(R.id.suggestFilm_clearBtn)
      ImageView suggestFilm_clearBtn;
      @BindView(R.id.suggestFilm_recyclerView)
      RecyclerView suggestFilm_recyclerView;
      @BindView(R.id.suggestFilm_recyclerViewProgress)
      ProgressBar suggestFilm_recyclerViewProgress;
      @BindView(R.id.suggestFilm_noDataText)
      TextView suggestFilm_noDataText;
      @BindView(R.id.newsPageLoadLay)
      RelativeLayout newsPageLoadLay;
      @BindView(R.id.suggestFilm_recyclerViewSendUser)
      RecyclerView suggestFilm_recyclerViewSendUser;
      @BindView(R.id.suggestFilm_buttonsSendCard)
      CardView suggestFilm_buttonsSendCard;
      private Context context;
      private SuggestFilmAdapter suggestFilmAdapter;
      private List&lt;Result&gt; model = new ArrayList&lt;&gt;();
      private ArrayList&lt;SuggestFilmAddUser&gt; suggestFilmAddUserList = new ArrayList&lt;&gt;();
      private SuggestFilmUserAdapter suggestFilmUserAdapter;
      private InterfaceApi api;
      private SharedPrefrencesHandler prefrencesHandler;
      private String token;
      private GridLayoutManager gridLayoutManager;
      private LinearLayoutManager linearLayoutManager;
      private List&lt;Integer&gt; usersListSend = new ArrayList&lt;&gt;();
      private SuggestFilmAddUser suggestFilmAddUser;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_suggest_film);
          //Initialize
          ButterKnife.bind(this);
          context = this;
          prefrencesHandler = new SharedPrefrencesHandler(context);
          api = ApiClient.getClient().create(InterfaceApi.class);
          suggestFilmAdapter = new SuggestFilmAdapter(context, model, this);
          gridLayoutManager = new GridLayoutManager(context, 3);
          linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
          //Get token
          token = prefrencesHandler.getFromShared(SharedPrefrencesKeys.TOKEN.name());
          //Set toolbar title
          toolbarTitleTxt.setText(context.getResources().getString(R.string.SuggestToFollowers));
          //Init followers recyclerView
          suggestFilm_recyclerView.setLayoutManager(gridLayoutManager);
          suggestFilm_recyclerView.setHasFixedSize(true);
          //Init send user recyclerView
          suggestFilm_recyclerViewSendUser.setLayoutManager(linearLayoutManager);
          suggestFilm_recyclerViewSendUser.setHasFixedSize(true);
          //Init Send user adapter
          suggestFilmUserAdapter = new SuggestFilmUserAdapter(context, suggestFilmAddUserList, this);
          suggestFilm_recyclerViewSendUser.setAdapter(suggestFilmUserAdapter);
          //Load more
          newsPageLoadLay.setVisibility(View.GONE);
          suggestFilm_recyclerView.setOnScrollListener(new EndlessRecyclerGridPage1(gridLayoutManager) {
              @Override
              public void onLoadMore(int current_page) {
  
                  newsPageLoadLay.setVisibility(View.VISIBLE);
  
                  Call&lt;SeriesWhoWatchedResponse&gt; call = api.getSuggestFilmUsers(token, filmSendData("", 10, current_page));
  
                  call.enqueue(new Callback&lt;SeriesWhoWatchedResponse&gt;() {
                      @Override
                      public void onResponse(Call&lt;SeriesWhoWatchedResponse&gt; call, Response&lt;SeriesWhoWatchedResponse&gt; response) {
                          if (response.body().getData() != null &amp;&amp; response.body().getStatusCode() != 401
                                  &amp;&amp; response.body().getStatusCode() != 402) {
                              if (response.body().getData().getResult().size() &gt; 0) {
                                  suggestFilmAdapter.addNewItem(response.body().getData().getResult());
                                  //Gone no explore
                                  newsPageLoadLay.setVisibility(View.GONE);
                              }
                          } else {
                              prefrencesHandler.remove(SharedPrefrencesKeys.TOKEN.name());
                              startActivity(new Intent(context, LoginActivity.class));
                          }
  
                          newsPageLoadLay.setVisibility(View.GONE);
                      }
  
                      @Override
                      public void onFailure(Call&lt;SeriesWhoWatchedResponse&gt; call, Throwable t) {
                          newsPageLoadLay.setVisibility(View.GONE);
                      }
                  });
              }
          });
          //Get user data
          getUserData("", 1);
      }
  
      private void getUserData(String search, int page) {
          suggestFilm_recyclerViewProgress.setVisibility(View.VISIBLE);
          Call&lt;SeriesWhoWatchedResponse&gt; call = api.getSuggestFilmUsers(token, filmSendData(search, 10, page));
          call.enqueue(new Callback&lt;SeriesWhoWatchedResponse&gt;() {
              @Override
              public void onResponse(Call&lt;SeriesWhoWatchedResponse&gt; call, Response&lt;SeriesWhoWatchedResponse&gt; response) {
                  if (response.body().getData() != null) {
                      if (response.body().getData().getResult().size() &gt; 0) {
                          model.clear();
                          model.addAll(response.body().getData().getResult());
                          suggestFilmAdapter.notifyDataSetChanged();
                          suggestFilm_recyclerView.setAdapter(suggestFilmAdapter);
                          suggestFilm_noDataText.setText("");
                      } else {
                          model.clear();
                          suggestFilmAdapter.notifyDataSetChanged();
                          suggestFilm_recyclerView.setAdapter(suggestFilmAdapter);
                          suggestFilm_noDataText.setText(context.getResources().getString(R.string.noFollowersYet));
                      }
                  }
                  suggestFilm_recyclerViewProgress.setVisibility(View.GONE);
              }
  
              @Override
              public void onFailure(Call&lt;SeriesWhoWatchedResponse&gt; call, Throwable t) {
                  suggestFilm_recyclerViewProgress.setVisibility(View.GONE);
              }
          });
      }
  
      private SuggestFilmSendData filmSendData(String search, int size, int page) {
          SuggestFilmSendData sendData = new SuggestFilmSendData();
          sendData.setKeyword(search);
          sendData.setPageIndex(page);
          sendData.setPageSize(size);
  
          return sendData;
      }
  
      @Override
      public void onSend(int Id, String name, String image) {
          suggestFilmAddUser = new SuggestFilmAddUser();
          suggestFilmAddUser.setId(Id);
          suggestFilmAddUser.setName(name);
          suggestFilmAddUser.setImage(image);
          //Add to list only once item
          for (SuggestFilmAddUser idList : suggestFilmAddUserList) {
              if (idList.getId() == suggestFilmAddUser.getId()) {
                  return;
              }
          }
          suggestFilmAddUserList.add(suggestFilmAddUser);
          if (suggestFilmAddUserList.size() &gt; 0) {
              suggestFilm_buttonsSendCard.setCardBackgroundColor(ContextCompat.getColor(context, R.color.colorAccent));
              suggestFilm_buttonsSendCard.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      getSuggestList();
                  }
              });
          }
          suggestFilmUserAdapter.notifyItemInserted(suggestFilmAddUserList.size() - 1);
          suggestFilm_recyclerViewSendUser.setVisibility(View.VISIBLE);
  
          for (SuggestFilmAddUser suggest : suggestFilmAddUserList) {
              if (suggest.getId() == suggestFilmAddUser.getId()) {
                  Log.e("SuggestLog", suggest.getId() + "");
                  usersListSend.add(suggest.getId());
                  return;
              }
          }
      }
  
      @Override
      public void onDelete(int Id) {
          if (usersListSend.size() &gt; 0) {
              usersListSend.remove(Id);
          }
  
          Toast.makeText(context, "" + Id, Toast.LENGTH_SHORT).show();
      }
  
      private void getSuggestList() {
          for (SuggestFilmAddUser suggest : suggestFilmAddUserList) {
              if (suggest.getId() == suggestFilmAddUser.getId()) {
                  Toast.makeText(context, "" + usersListSend, Toast.LENGTH_SHORT).show();
                  return;
              }
          }
      }
  </code></pre>
  
  <p><strong>For add user Adapter:</strong></p>
  
  <pre><code>public class SuggestFilmAdapter extends RecyclerView.Adapter&lt;SuggestFilmAdapter.ViewHolder&gt; {
  
      private Context context;
      private List&lt;Result&gt; model;
      private SuggestedListener suggestedListener;
  
      public SuggestFilmAdapter(Context context, List&lt;Result&gt; model, SuggestedListener suggestedListener) {
          this.context = context;
          this.model = model;
          this.suggestedListener = suggestedListener;
      }
  
      @Override
      public SuggestFilmAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_suggest_film_users_followers, parent, false);
  
          return new SuggestFilmAdapter.ViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(final SuggestFilmAdapter.ViewHolder holder, final int position) {
          //Name
          holder.row_suggestFilmProfileName.setText(model.get(position).getName());
          //Image
          Glide.with(context)
                  .load(model.get(position).getImageUrl())
                  .asBitmap()
                  .placeholder(R.drawable.default_image)
                  .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                  .override(300, 300)
                  .into(new BitmapImageViewTarget(holder.row_suggestFilmProfileImage) {
                      @Override
                      protected void setResource(Bitmap resource) {
                          if (context == null) return;
  
                          RoundedBitmapDrawable circularBitmapDrawable =
                                  RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                          circularBitmapDrawable.setCircular(true);
                          holder.row_suggestFilmProfileImage.setImageDrawable(circularBitmapDrawable);
                      }
                  });
          //Is Mutual
          if (model.get(position).getIsMutual()) {
              holder.row_suggestFilmIsOk.setVisibility(View.VISIBLE);
          } else {
              holder.row_suggestFilmIsOk.setVisibility(View.GONE);
          }
          holder.row_suggestedLay.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  suggestedListener.onSend(model.get(position).getUserId(),
                          model.get(position).getName(),
                          model.get(position).getImageUrl());
              }
          });
      }
  
      @Override
      public int getItemCount() {
          return model.size();
      }
  
      public void addNewItem(List&lt;Result&gt; newContent) {
          int start = this.model.size();
          int end = newContent.size();
          model.addAll(newContent);
          notifyDataSetChanged();
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
  
          private ImageView row_suggestFilmProfileImage, row_suggestFilmIsOk;
          private TextView row_suggestFilmProfileName;
          private RelativeLayout row_suggestedLay;
  
          public ViewHolder(View itemView) {
              super(itemView);
  
              row_suggestFilmProfileImage = (ImageView) itemView.findViewById(R.id.row_suggestFilmProfileImage);
              row_suggestFilmIsOk = (ImageView) itemView.findViewById(R.id.row_suggestFilmIsOk);
              row_suggestFilmProfileName = (TextView) itemView.findViewById(R.id.row_suggestFilmProfileName);
              row_suggestedLay = (RelativeLayout) itemView.findViewById(R.id.row_suggestedLay);
          }
      }
  }
  </code></pre>
  
  <p><strong>For delete user adapter:</strong> </p>
  
  <pre><code>public class SuggestFilmUserAdapter extends RecyclerView.Adapter&lt;SuggestFilmUserAdapter.ViewHolder&gt; {
  
      private Context context;
      private ArrayList&lt;SuggestFilmAddUser&gt; model;
      private SuggestedDeleteListener deleteListener;
  
      public SuggestFilmUserAdapter(Context context, ArrayList&lt;SuggestFilmAddUser&gt; model, SuggestedDeleteListener deleteListener) {
          this.context = context;
          this.model = model;
          this.deleteListener = deleteListener;
      }
  
      @Override
      public SuggestFilmUserAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_suggest_film_users_add, parent, false);
  
          return new SuggestFilmUserAdapter.ViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(final SuggestFilmUserAdapter.ViewHolder holder, final int position) {
          //Name
          holder.rowSuggestAddUser_name.setText(model.get(position).getName());
          //Image
          Glide.with(context)
                  .load(model.get(position).getImage())
                  .asBitmap()
                  .placeholder(R.drawable.default_image)
                  .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                  .override(300, 300)
                  .into(new BitmapImageViewTarget(holder.rowSuggestAddUser_image) {
                      @Override
                      protected void setResource(Bitmap resource) {
                          if (context == null) return;
  
                          RoundedBitmapDrawable circularBitmapDrawable =
                                  RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                          circularBitmapDrawable.setCircular(true);
                          holder.rowSuggestAddUser_image.setImageDrawable(circularBitmapDrawable);
                      }
                  });
          //Cancel btn
          holder.rowSuggestAddUser_cancelImage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  deleteItem(position);
                  deleteListener.onDelete(model.get(position).getId());
              }
          });
      }
  
      private void deleteItem(int position) {
          model.remove(position);
          notifyItemRemoved(position);
          notifyItemRangeChanged(position, model.size());
      }
  
      @Override
      public int getItemCount() {
          return model.size();
      }
  
      public void addNewItem(ArrayList&lt;SuggestFilmAddUser&gt; newContent) {
          int start = this.model.size();
          int end = newContent.size();
          model.addAll(newContent);
          notifyDataSetChanged();
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
  
          private ImageView rowSuggestAddUser_image, rowSuggestAddUser_cancelImage;
          private TextView rowSuggestAddUser_name;
          private RelativeLayout rowSuggestAddUser_lay;
  
          public ViewHolder(View itemView) {
              super(itemView);
  
              rowSuggestAddUser_image = (ImageView) itemView.findViewById(R.id.rowSuggestAddUser_image);
              rowSuggestAddUser_cancelImage = (ImageView) itemView.findViewById(R.id.rowSuggestAddUser_cancelImage);
              rowSuggestAddUser_name = (TextView) itemView.findViewById(R.id.rowSuggestAddUser_name);
              rowSuggestAddUser_lay = (RelativeLayout) itemView.findViewById(R.id.rowSuggestAddUser_lay);
          }
      }
  }
  </code></pre>
  
  <p><strong>LogCat error :</strong> </p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.app.test, PID: 28516
  java.lang.IndexOutOfBoundsException: Invalid index 18, size is 2
  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
  at java.util.ArrayList.remove(ArrayList.java:403)
  at com.app.test.Activities.SuggestFilmActivity.onDelete(SuggestFilmActivity.java:222)
  at com.app.test.Adapters.SuggestFilm.SuggestFilmUserAdapter$2.onClick(SuggestFilmUserAdapter.java:76)
  at android.view.View.performClick(View.java:4764)
  at android.view.View$PerformClick.run(View.java:19844)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:135)
  at android.app.ActivityThread.main(ActivityThread.java:5349)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
  </code></pre>
  
  <p><strong>Show error for this line in onDelete:</strong> </p>
  
  <pre><code>usersListSend.remove(Id);
  </code></pre>
  
  <p>Please help me, I am amateur and really need this help. please . Thanks, all &lt;3</p>