Problems while setting the ImageView source in the ItemLayout of a ListView
<p>i have a problem while setting the source of an ImageView that is inside an Item of a ListView. The problem is as follows:</p>

<p>In my XML LayoutFile for the ListItems i have an ImageView and a TextView:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:paddingLeft="10dp"
android:orientation="horizontal"&gt;

&lt;ImageView android:id="@+id/actionState"
    android:layout_width="12dp"
    android:layout_height="12dp"
    android:layout_gravity="center_vertical"
    android:src="@drawable/check_lightgrey"
    android:layout_marginRight="5dp"/&gt;

&lt;TextView android:id="@+id/actionText"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>In my res/drawable folder i have the two files check_lightgrey.png and check_green.png. Drawing the ListView with an ArrayAdapter in that way that every ListItem consists of the check_lightgrey.png followed by the coresponding text works fine. </p>

<p>When the user clicks on a ListItem i want change the source from the ImageView of this ListItem from check_lightgrey.png to check_green.png</p>

<p>The Code of my setOnItemClickListener in my ListActivity looks like this:</p>

<pre><code>ListView listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
            ImageView imageView = (ImageView) v.findViewById(R.id.actionState);
            imageView.setImageResource(R.drawable.check_green);
        }
    });
</code></pre>

<p>This works fine as long as the List is not so full that scrolling is needed. If there are that many ListItems that you need to scroll, then there is a bug when clicking on a ListItem: Not only the source of the ImageView in the clicked ListItem is set but also the source of the ImageViews of ListItems that are not visible because they are out of the current view.</p>

<p>It sounds a little confusing, but i will give an example:</p>

<ul>
<li>There are 56 items in the Listview</li>
<li>without scrolling you can see the first 13 Items</li>
<li>now click on Item 1 -> the source of the ImageView changes as aspected</li>
<li>now scrolling down the source of the ImageView of second Item (Item 15) that was not visible before has also changed </li>
<li>the same thing is with Item 29 and with Item 43</li>
<li>as you can see there is always a difference of 14</li>
</ul>

<p>The same effect exists when changing the oriantation of the device to landscape. The Only thing that changes is the difference that is 7.</p>

<p>I searched for a conclusion but didn't find anything. So it woud be nice if anybody could help me or give me a hint.</p>

<p>greetings</p>
