title: Android: Custom Adapter with ViewHolder, OnCheckedChangedListener and TextChangedListener
body: <p>I'm new to Android and Java programming and I've come across a problem recently. I've been searching an answer for hours, but I wasn't successful.
  I have a custom ListView and a custom adapter, with a row containing a CheckBox and an EditText. Whenever it is displayed for the first time, it is OK, but when I scroll down, it starts to change the values of the CheckBox and the EditText.</p>
  
  <p>Here is my row_edit.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;EditText
          android:id="@+id/bonus"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:inputType="numberSigned"
          android:gravity="right"
          android:selectAllOnFocus="true"
          android:textSize="16sp" /&gt;
  
      &lt;CheckBox
          android:id="@+id/checkBox_person"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_toLeftOf="@id/bonus"
          android:textSize="16sp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Item_edit (item of adapter):</p>
  
  <pre><code>public class Item_edit {
      private String meno;
      private boolean ucast;
      private int bonus;
  
      public Item_edit(String meno, boolean ucast, int bonus) {
          super();
          this.meno = meno;
          this.ucast = ucast;
          this.bonus = bonus;
      }
  
      public String getMeno() {
          return meno;
      }
  
      public boolean getUcast() {
          return ucast;
      }
  
      public int getBonus() {
          return bonus;
      }
  
      public void setMeno(String meno) {
          this.meno = meno;
      }
  
      public void setUcast(boolean ucast) {
          this.ucast = ucast;
      }
  
      public void setBonus(int bonus) {
          this.bonus = bonus;
      }
  }
  </code></pre>
  
  <p>The ListView wasn't smooth, when I was scrolling and that is why I decided to use a ViewHolder.
  Adapter_edit:</p>
  
  <pre><code>public class Adapter_edit extends ArrayAdapter&lt;Item_edit&gt; {
      private final Context context;
      private final ArrayList&lt;Item_edit&gt; itemsArrayList;
      private final Edit edit;
  
      public Adapter_edit(Context context, ArrayList&lt;Item_edit&gt; itemsArrayList, Edit edit) {
  
          super(context, R.layout.row_edit, itemsArrayList);
          this.edit = edit;
          this.context = context;
          this.itemsArrayList = itemsArrayList;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          ViewHolder holder = null;
  
          if (convertView == null) {
              LayoutInflater inflater = (LayoutInflater) context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = inflater.inflate(R.layout.row_edit, parent, false);
              holder = new ViewHolder();
              //Log.e("NewHolder", "position = " + position);
              holder.checkBox = (CheckBox) convertView
                      .findViewById(R.id.checkBox_person);
              holder.bonus = (EditText) convertView.findViewById(R.id.bonus);
              convertView.setTag(holder);
  
              holder.checkBox.setText(itemsArrayList.get(position).getMeno());
              holder.checkBox.setChecked(itemsArrayList.get(position).getUcast());
              holder.bonus.setText(Integer.toString(itemsArrayList.get(position)
                      .getBonus()));
  
              holder.checkBox
                      .setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
                          @Override
                          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  
                              itemsArrayList.get(position).setUcast(isChecked);
                          }
                      });
  
              holder.bonus.addTextChangedListener(new TextWatcher() {
  
                  @Override
                  public void onTextChanged(CharSequence s, int start, int before, int count) {
                      try {
  
                          if (itemsArrayList.get(position).getBonus() != Integer
                                  .parseInt(s.toString()) &amp;&amp; !edit
                                  .getUcast(position)) {
                              itemsArrayList.get(position).setBonus(
                                      Integer.parseInt(s.toString()));
                              itemsArrayList.get(position).setUcast(true);
                          }
                      }
                      catch (NumberFormatException e) {
                          itemsArrayList.get(position).setBonus(0);
                      }
  
                  }
  
                  @Override
                  public void afterTextChanged(Editable s) {
                  }
  
                  @Override
                  public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                  }
              });
  
          }
  
          else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          holder.checkBox.setText(itemsArrayList.get(position).getMeno());
          holder.checkBox.setChecked(itemsArrayList.get(position).getUcast());
          holder.bonus.setText(Integer.toString(itemsArrayList.get(position)
                  .getBonus()));
  
          return convertView;
      }
  
      static class ViewHolder {
          CheckBox checkBox;
          EditText bonus;
      }
  }
  </code></pre>
  
  <p>After debugging with LogCat I know that there are only 8 holders generated (because there are (0-7) items that fit my screen). These are being reused, when I scroll down. There are no OnCheckedChangeListeners and TextChangedListeners created for items with position greater than 7.</p>
  
  <p>I have no idea what to do. Can someone help me?</p>