title: how to add a listener for checkboxes in an adapter view, Android, ArrayAdapter, onCheckedChanged, OnCheckedChangeListener
body: <p><img src="https://i.stack.imgur.com/lAOuU.png" alt="enter image description here"></p>
  
  <p>I have a listView that by way of an ArrayAdapter is populated by small xml sub views.  each small view only has two things inside, a checkbox and a string label next to it.</p>
  
  <p>i want to set an onCheckedChanged listener to capture the event of the user checking or unchecking the checkboxes.</p>
  
  <p>for example the listener shown here:</p>
  
  <pre><code> listView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
   @Override
   public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  
   Toast.makeText(this, "box has been checked", Toast.LENGTH_SHORT).show();
  
   }
  </code></pre>
  
  <p>}</p>
  
  <p>where do I put the listener code? and how do I set it up?</p>
  
  <p>code for the ArrayAdapter:</p>
  
  <pre><code>  public class MobileArrayAdapter extends ArrayAdapter&lt;CheckBoxInfo&gt;{
      CheckBoxInfo[] objects;
      Context context;
      int textViewResourceId;
  
      public MobileArrayAdapter(Context context, int textViewResourceId,
          CheckBoxInfo[] objects) {
          super(context, textViewResourceId, objects);
          this.context = context;
          this.textViewResourceId = textViewResourceId;
          this.objects = objects;
  
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row_layout_view = convertView;
  
  
              if ((row_layout_view == null)){
  
  
                  LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  row_layout_view = inflater.inflate(R.layout.row_layout, null);
              }   
  
            //CheckBoxInfo item = objects.get(position);  // for arrayList
              CheckBoxInfo item = objects[position];
  
              if(item != null){
  
              TextView textView = (TextView) row_layout_view.findViewById(R.id.textView1);
              CheckBox checkBox = (CheckBox) row_layout_view.findViewById(R.id.checkBox1);
  
              if(item !=null){
              textView.setText(item.checkBoxName);
              checkBox.setChecked(item.checkBoxState);
                 }
              }
              return row_layout_view;
      }
  
  
  }
  </code></pre>