title: Why data model is not updated when ListView row with a CheckBox gets off-screen?
body: <p>While this is the behaviour that I want, could someone explain me why does it happen?</p>
  
  <p>I have a <code>ListView</code> with custom rows consisting of a <code>CheckBox</code> and a <code>TextView</code>. Here is row layout code:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="match_parent"
      android:layout_width="match_parent"
      android:orientation="horizontal"&gt;
  
      &lt;CheckBox
          android:id="@+id/shop_list_checkbox"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
      &lt;TextView
          android:id="@+id/shop_list_textView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Sample text"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Then I have this simple data model (omitted some methods and fields), basically a shop with a name and selection state:</p>
  
  <pre><code>public class ShopListItem {
  
      //name of the shop
      private String name;
  
      //shop selection state
      private boolean isSelected;
  
      public ShopListItem(String shopKey, String name, boolean isSelected) {
          this.shopKey = shopKey;
          this.name = name;
          this.isSelected = isSelected;
      }
  
      public boolean isSelected() {
          return isSelected;
      }
  
      public void setSelected(boolean selectionState) {
          this.isSelected = selectionState;
      }
  }
  </code></pre>
  
  <p>And here is relevant code from my custom <code>ArrayAdapter</code>:</p>
  
  <pre><code>public View getView(int position, View convertView, @NonNull ViewGroup parent) {
  
          // Temporary view to be returned as converterView
          View view;
  
          // Checking if view is reused or not
          if (convertView == null) { //new view is generated
  
              // Inflate new view and associate its views with viewHodler
              view = inflater.inflate(R.layout.row_shop_list, parent, false);
              final ViewHolder viewHolder = new ViewHolder();
              viewHolder.shopNameTextView = (TextView) view.findViewById(R.id.shop_list_textView);
              viewHolder.checkBox = (CheckBox) view.findViewById(R.id.shop_list_checkbox);
  
              // Asign check change listener
              viewHolder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                  @Override
                  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                      Log.i("i", "isChecked value is: "+isChecked+", buttonView.isChecked() value is: "+buttonView.isChecked());
  
                      // Get reference to the shop (data model) of checked row
                      ShopListItem shop = (ShopListItem) viewHolder.checkBox.getTag();
  
                      // Update selection state in data model
                      shop.setSelected(buttonView.isChecked());
  
                      listSelections(shopsArrayList);
  
                  }
              });
  
  
              // Store viewHolder inside temporary view
              view.setTag(viewHolder);
  
              // Store reference to a shop (data model) of this row in the checkbox reference
              viewHolder.checkBox.setTag(shopsArrayList.get(position));
  
          } else {  //existing view reused
  
              // Assign view from adapter to temporary view
              view = convertView;
  
              // Get viewholder from view which was stored while generating new view
              ViewHolder storedHolder = (ViewHolder) view.getTag();
  
              //Store reference to a shop (data model) of this row in the checkbox reference
              storedHolder.checkBox.setTag(shopsArrayList.get(position));
  
          }
  
          // Get viewholder from view (from new view or converview)
          ViewHolder holder = (ViewHolder) view.getTag();
  
          // Populate holder references with data from shops array list
          holder.shopNameTextView.setText(shopsArrayList.get(position).getName());
          holder.checkBox.setChecked(shopsArrayList.get(position).isSelected());
  
          //return view
          return view;
  
      }
  </code></pre>
  
  <p>The mystery lies within <code>OnCheckedChangeListener</code>. Whenever I click the checkbox of first row, listener receives correct state and updates first item of the shops array list (either to true or false). But, if I leave first checkbox checked and scroll list down, as soon as first row gets off-screen,  <code>OnCheckedChangeListener</code> is called with the state <code>false</code>, but first item of the shops array list is not updated to <code>false</code>. Why is this happening? Why it gets updated only when click the box, but not when its called due being hidden?</p>