title: Android ListView with a checkbox and multiple TextViews per list item
body: <p>I'm quite new to programming Android apps and have now run into a problem for which I couldn't find an explanation (nor an easy solution):</p>
  
  <p>I want to display a list of files containing a checkbox, the filename and filesize. The Android developer docs contain a tutorial on how to implement a ListView and I also managed to change the ListItem-layout to contain the checkbox and two TextViews.</p>
  
  <p>The list looks just how it should, but when I check a checkbox, every seventeenth or so checkbox is checked, too. It looks like the ListView stores the values of the checkboxes page-wise, so that when the values are changed on one page, they change on every page.</p>
  
  <p>Looking for a workaround, I discovered that one could use <code>android.R.layout.simple_list_item_multiple_choice</code> instead of a custom layout - which indeed works fine, but contains only one TextView and is therefore useless for me. Some sites also suggest creating a custom type of TextView (consisting of a LinearLayout, the CheckBox and the TextViews needed) for this, but I would like to avoid having to an extra class just for the ListView to work properly.</p>
  
  <p>I would be glad if anyone could tell me where my error is or whether there is a workaround for this.</p>
  
  <p>My current HelloListViewActivity.java:</p>
  
  <pre><code>public class HelloListViewActivity extends ListActivity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
  
        setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, R.id.container, COUNTRIES));
  
        ListView lv = getListView();
        lv.setTextFilterEnabled(true);
  
        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
              int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(), ((TextView) (((LinearLayout) view).findViewById(R.id.container))).getText(),
                Toast.LENGTH_SHORT).show();
          }
        });
      }
  
      static final String[] COUNTRIES = new String[] {
          "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra"
                      /* etc. */
          };
  }
  </code></pre>
  
  <p>And list_item.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1"&gt;
      &lt;CheckBox 
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:focusable="false"
          android:textSize="16sp" /&gt;
      &lt;TextView
          android:gravity="center_horizontal"
          android:layout_weight="1"
          android:text="Text"
          android:layout_width="0dip"
          android:layout_height="fill_parent"
          android:padding="10dp"
          android:textSize="16sp"
          android:id="@+id/container" /&gt;
      &lt;TextView
          android:text="---"
          android:gravity="center_horizontal"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>