title: Removing an item from RecyclerView
body: <p>I have a problem when I am removing an item from my list in my RecycerView. I want to do the following functionality. When I press a checkbox in my RecycerView list the item is to be removed from the list. Basically this works when I press some of the top/bottom checkboxes, but when I press some in-between I have other checkboxes are marked as Checked without even touching them. I don't know where this problem comes from.</p>
  
  <p><img src="https://i.stack.imgur.com/JeNty.png" alt="enter image description here"></p>
  
  <p>This is my code in my adapter:</p>
  
  <pre><code>public class ShoppingListAdapter extends RecyclerView.Adapter&lt;ShoppingListAdapter.ShoppingListViewHolder&gt; {
  private ArrayList&lt;Item&gt; mItems;
  private Context mContext;
  
  public ShoppingListAdapter(Context context, ArrayList&lt;Item&gt; items) {
      mItems = items;
      mContext = context;
  }
  
  @Override
  public ShoppingListViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
      View view = LayoutInflater.from(mContext).inflate(R.layout.shopping_list_item,viewGroup,false);
      ShoppingListViewHolder viewHolder = new ShoppingListViewHolder(view);
  
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder(ShoppingListViewHolder shoppingListViewHolder, int position) {
      shoppingListViewHolder.bindShoppingList(mItems.get(position));
  }
  
  @Override
  public int getItemCount() {
      return mItems.size();
  }
  
  public class ShoppingListViewHolder extends RecyclerView.ViewHolder implements CompoundButton.OnCheckedChangeListener{
      public TextView mShoppingListItem;
      public CheckBox mCheckBox;
  
      public ShoppingListViewHolder(View itemView) {
          super(itemView);
          mShoppingListItem = (TextView) itemView.findViewById(R.id.shoppingListItem);
          mCheckBox = (CheckBox) itemView.findViewById(R.id.shoppingListCheckBox);
          mCheckBox.setOnCheckedChangeListener(this);
      }
  
      public void bindShoppingList(Item item){
          mShoppingListItem.setText(item.getItemDescription());
      }
  
  
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          removeAt(getAdapterPosition(),this);
      }
  }
  
  public void removeAt(int position,ShoppingListViewHolder viewHolder) {
      mItems.remove(position);
      notifyItemRemoved(position);
  }
  </code></pre>
  
  <p>This is my code in MainActivity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  private Toolbar mToolbar;
  private RecyclerView mRecyclerView;
  private ArrayList&lt;Item&gt; shoppingListItems;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mToolbar = (Toolbar)findViewById(R.id.tool_bar);
      setSupportActionBar(mToolbar);
      mRecyclerView = (RecyclerView)findViewById(R.id.recyclerView);
      shoppingListItems = new ArrayList&lt;&gt;();
      shoppingListItems.add(new Item("Apples"));
      shoppingListItems.add(new Item("Bred"));
      shoppingListItems.add(new Item("Potatoes"));
      shoppingListItems.add(new Item("Muffins"));
      shoppingListItems.add(new Item("Crackers"));
      shoppingListItems.add(new Item("Spaghetti"));
      shoppingListItems.add(new Item("Plastic Bags"));
      shoppingListItems.add(new Item("Deodorant"));
      shoppingListItems.add(new Item("Razors"));
      shoppingListItems.add(new Item("Shampoo"));
      shoppingListItems.add(new Item("Tooth brushes"));
      shoppingListItems.add(new Item("Butter"));
      shoppingListItems.add(new Item("Bagels"));
      shoppingListItems.add(new Item("Coconut water"));
      shoppingListItems.add(new Item("Tomatoes"));
  
      ShoppingListAdapter adapter = new ShoppingListAdapter(this,shoppingListItems);
      mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));
      mRecyclerView.setAdapter(adapter);
      mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  </code></pre>