title: How to set OnCheckedChangeListener to a checkbox of a cell in a listview
body: <p>Hi guys I am trying to set an <code>OnCheckedChangeListener</code> on a <code>CheckBox</code> declared in the <code>xml</code> file that represent the single row of the <code>ListView</code> (<strong>item_todo.xml</strong>), here the code of the checkbox:</p>
  
  <pre><code>&lt;CheckBox
      android:id="@+id/checkBox1"
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:layout_gravity="center_vertical"
      android:text="" /&gt;
  </code></pre>
  
  <p>Here the part of code of the listview (<strong>fragment_bacheca.xml</strong>):</p>
  
  <pre><code>&lt;ListView
          android:id="@+id/listView1"
          android:layout_marginTop="20dp"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  </code></pre>
  
  <p>Then I use a custom adapter:`</p>
  
  <pre><code>public class TaskListAdapter extends ArrayAdapter&lt;TaskCell&gt;{
  
      public TaskListAdapter(Context context, int textViewResourceId, List&lt;TaskCell&gt; objects){
          super(context, textViewResourceId, objects);
      }
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = (LayoutInflater) getContext()
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = inflater.inflate(R.layout.item_todo, null);
          TextView task_subject = (TextView) convertView.findViewById(R.id.task_subject);
          TextView task_type = (TextView) convertView.findViewById(R.id.task_type);
          TextView task_data = (TextView) convertView.findViewById(R.id.task_data);
          CheckBox cb = (CheckBox) convertView.findViewById(R.id.checkBox1);
  
          TaskCell t = getItem(position);
          task_subject.setText(t.getMateria());
          task_type.setText(t.getTipo());
          task_data.setText(t.getData());
          if(t.getFatto().equals("1")) {
              cb.setChecked(true);
              task_subject.setPaintFlags(task_subject.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
          }
          else{
              cb.setChecked(false);
          }
  
          return convertView;
      }
  </code></pre>
  
  <p><code>TaskCell</code> is the class for the the data of the <strong>todo_item</strong>.</p>
  
  <p>And here the code of the fragment where I call the listener:</p>
  
  <pre><code>taskView = getActivity().getLayoutInflater().inflate(R.layout.item_todo, null);
      checkbox_task = (CheckBox) taskView.findViewById(R.id.checkBox1);
  
      checkbox_task.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
              adapter.notifyDataSetChanged();
          }
      });
  
      list = new LinkedList&lt;&gt;();
      adapter = new TaskListAdapter(getContext(), R.layout.item_todo, list);
      lv.setAdapter(adapter);
  </code></pre>
  
  <p>The problem is that nothing happened and with the debug i saw that the <code>onCheckedChanged</code> is never reached.</p>
  
  <p>Anyone knows why? Thank you all</p>