title: IndexOutOfBoundsException in case of deleting data from recyclerView using FirebaseRecyclerAdapter
body: <p>I am using FirebaseRecyclerAdapter to use a dynamic recyclerView in my application. In each of the recycler Item, i have a delete button to delete the particular recyclerView Item. But  some times I am getting an exception while deleting the value. I tried most of the solutions on stack overflow to no change. Need your help. Below I am posting the adapter code.</p>
  
  <p>The exception that I am getting is :</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
                                                                              at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
                                                                              at java.util.ArrayList.get(ArrayList.java:308)
                                                                              at com.firebase.ui.database.FirebaseArray.getItem(FirebaseArray.java:52)
                                                                              at com.firebase.ui.database.FirebaseRecyclerAdapter.getRef(FirebaseRecyclerAdapter.java:150)
  </code></pre>
  
  <p>slcListFragment.java:</p>
  
  <pre><code> slcList.setLayoutManager(llm);
       adapter = new FirebaseRecyclerAdapter&lt;Slc, viewHolder&gt;(
              Slc.class,
              R.layout.single_slc_row,
              viewHolder.class,
              FirebaseDatabase.getInstance().getReference()) {
          @Override
          protected void populateViewHolder(final viewHolder viewHolder, final Slc model, final int position)
          {
  
              //expand collapse
              viewHolder.expand.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v)
                  {
                      // ViewAnimationsUtils.expand(viewHolder.inv);
                      viewHolder.collapse.setVisibility(View.VISIBLE);
                      viewHolder.inv.setVisibility(View.VISIBLE);
                      viewHolder.expand.setVisibility(View.GONE);
                  }
              });
              viewHolder.collapse.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v)
                  {
                      // ViewAnimationsUtils.collapse(inv);
                      viewHolder.inv.setVisibility(View.GONE);
                      viewHolder.expand.setVisibility(View.VISIBLE);
                      viewHolder.collapse.setVisibility(View.GONE);
                  }
              });
              String s=adapter.getRef(position).getKey();
              viewHolder.name.setText(s);
  
              //dimming get
              viewHolder.dimming.setProgress(model.getDimming_val());
  
              //on off get
              if(model.getOn_off()==1)
              {
                  viewHolder.onOff.setChecked(true);
              }
              else if(model.getOn_off()==0)
              {
                  viewHolder.onOff.setChecked(false);
              }
  
              //dimming set
              viewHolder.dimming.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                  @Override
                  public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
                  {
                      adapter.getRef(position).child("dimming_val").setValue(progress);
  
                  }
  
                  @Override
                  public void onStartTrackingTouch(SeekBar seekBar) {
  
                  }
  
                  @Override
                  public void onStopTrackingTouch(SeekBar seekBar) {
  
                  }
              });
  
              viewHolder.onOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
                  @Override
                  public void onCheckedChanged(CompoundButton buttonView,
                                               boolean isChecked) {
  
                      if(buttonView.isPressed() &amp;&amp;isChecked){
                          adapter.getRef(position).child("on_off").setValue(1);
  
  
                      }else{
                          adapter.getRef(position).child("on_off").setValue(0);
  
                      }
  
                  }
              });
              viewHolder.delete.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v)
                  {
                      final Dialog dialog = new Dialog(myContext);
                      dialog.setTitle("Delete Slc?");
                      dialog.setContentView(R.layout.delete_slc);
                      dialog.setCancelable(false);
                      Window window = dialog.getWindow();
                      if(window == null) return;
                      WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                      lp.copyFrom(dialog.getWindow().getAttributes());
                      lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                      lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                      lp.gravity = Gravity.CENTER;
                      dialog.getWindow().setAttributes(lp);
                      TextView delete = (TextView)dialog.findViewById(R.id.deleteSlc);
                      delete.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v)
                          {
                              int pos = viewHolder.getAdapterPosition();
                              ref.child(adapter.getRef(position).getKey()).removeValue();
  
                              notifyItemRemoved(pos);
  
                             // adapter.notifyDataSetChanged();
  
                              dialog.dismiss();
                          }
                      });
  
  
                      TextView dialogButton = (TextView) dialog.findViewById(R.id.canceld);
                      // if button is clicked, close the custom dialog
                      dialogButton.setOnClickListener(new View.OnClickListener() {
                          @Override
                          public void onClick(View v)
                          {
                              dialog.dismiss();
                          }
                      });
  
                      dialog.show();
  
                  }
              });
          }
      };
  
      slcList.setAdapter(adapter);
  </code></pre>