title: How to set ArrayList with isChecked in CheckBox android
body: <p>How to set data with checkbox when user clicks submit? I want to get all data within <code>isChecked()</code></p>
  
  <p>And I try this code which doesn't work.</p>
  
  <p>myadapter</p>
  
  <pre><code>viewHoder.cx_select_invite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          if (isChecked) {
              Log.d("ChatGroupInviteAdap", "onClick position: " + position);
              Log.d("ChatGroupInviteAdap", "onClick getFirstname: " + chatFriendsListModels.get(position).getFirstname());
              id = chatFriendsListModels.get(position).getId();
              ChatGroupInviteFragment.dataMember.add(id);
          }
  
          if (!isChecked) {
              id = chatFriendsListModels.get(position).getId();
              ChatGroupInviteFragment.dataMember.remove(id);
          }
  
      }
  });
  </code></pre>
  
  <p>myFragment</p>
  
  <p>user clicks submit when user checks finish</p>
  
  <pre><code>tx_submit.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          Log.d(TAG, "OnClick: " + ChatGroupInviteFragment.dataMember.size());
  
          for (int i=0;i&lt;ChatGroupInviteFragment.dataMember.size();i++){
              Log.d(TAG, "OnClick2 : " + ChatGroupInviteFragment.dataMember.get(i));
          }
      }
  });
  </code></pre>
  
  <p>I get error when user unChecked </p>
  
  <blockquote>
    <p>FATAL EXCEPTION: main
                                                                             Process: xxx.xx.x, PID: 20496
                                                                             java.lang.IndexOutOfBoundsException: Invalid index 36, size is 3</p>
  </blockquote>
  
  <pre><code>36 is id unChecked
  
  and 3 = size isChecked
  </code></pre>
  
  <p>How to set it?</p>