ListFragment onListItemClick strange behaviour

Monday, May 12, 2014

In my CustomList fragment I want to show an image inside item layout each time item is clicked:



public class CustomList extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
...

@Override
public void onListItemClick(ListView list, View view, int position, long id) {
super.onListItemClick(list, view, position, id);

ImageView imageToShow = (ImageView) view.findViewById(R.id.myImageId);
if (imageToShow != null) {
if (imageToShow.getVisibility() == View.INVISIBLE) {
imageToShow.setVisibility(View.VISIBLE);
}
}
}

...
}


The row item layout has an ImageView with visibility attribute set to "invisible"



<LinearLayout xmlns:android="http://ift.tt/nIICcg" xmlns:tooth="http://ift.tt/1oHZ6TL"
<!-- ... -->
<ImageView
android:id="@+id/myImageId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/image"
android:src="@drawable/ic_action_event"
android:visibility="invisible" />
</LinearLayout>


The problem is, when row item is clicked, the image appears for it, but also it appears for other item from the bottom of the list. So if I click item on position 0, the image appears also on item with position 7. I can't figure out what is the reason for that behaviour.







http://ift.tt/1olnRI3