Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:05:10+00:00 2026-05-23T14:05:10+00:00

i have a problem while setting the source of an ImageView that is inside

  • 0

i have a problem while setting the source of an ImageView that is inside an Item of a ListView. The problem is as follows:

In my XML LayoutFile for the ListItems i have an ImageView and a TextView:

<?xml version="1.0" encoding="utf-8"?>
<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">

<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"/>

<TextView android:id="@+id/actionText"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    />

</LinearLayout>

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.

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

The Code of my setOnItemClickListener in my ListActivity looks like this:

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

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.

It sounds a little confusing, but i will give an example:

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

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

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.

greetings

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:05:11+00:00Added an answer on May 23, 2026 at 2:05 pm

    First, it’s not a bug. It happens because ListView is trying to recycle views in order to be faster. So, in order to change the image of one of the rows you must change the data that is behind the list, update your adapter and call notifyDataSetChanged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this open-source library that I'm having some trouble fixing a problem... This
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
I have a problem while pasting my contents (or text) generated by Java code
I have a problem while executing a SSIS script component. To be honest I
I have a problem while scrolling images on tableview. I am getting a Signal
I have come across an annoying problem while writing some PHP4 code. I renamed
I have a flash file menu i am having problem while link it to
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
I have this problem I've been trying to tackle for a while. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.