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 5932339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:49:14+00:00 2026-05-22T14:49:14+00:00

I have a ListView with an ArrayAdapter holding rows with a Image and a

  • 0

I have a ListView with an ArrayAdapter holding rows with a Image and a String. This worked fine until I decided that the loading of the images was to slow so I could not load the images before showing the list. So I started to load the images in a separate thread using an AsyncTask.

I was very happy with the result until I started to scroll the list. Wrong images was loaded and it doesn’t look like it is a question of the image getting a while later. If I attempt to sort the list the problem goes really bad and none of the images is on the right row.

Any ideas of what I’m doing wrong?

public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ImageView imageView;
        TextView textView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.drink_list_row, null);
        }

        Drink drink = allItems.get(position);
        if (drink != null && v != null) {
            imageView = (ImageView) v.findViewById(R.id.picture);
            textView = (TextView) v.findViewById(R.id.drinkName);
            imageView.setVisibility(View.GONE);
            loadImageBitmap(drink, imageView);
            textView.setText(drink.getName());

            if (subItems != null && subItems.contains(drink)) {
                textView.setVisibility(View.VISIBLE);
                imageView.setVisibility(View.VISIBLE);
            } else {
                textView.setVisibility(View.GONE);
                imageView.setVisibility(View.GONE);
            }
        }
        return v;
    }
  • 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-22T14:49:14+00:00Added an answer on May 22, 2026 at 2:49 pm

    The problem comes from your convertView: it’s the same single instance that is used throughout the list, so when your asynchronous loading is complete, the image is changed when the listview is trying to paint a different item using the same convertView (or in that case, its child imageView).

    painting position 1, uses placeholder, starts loading image 1 asynchronously
    painting position 2, uses placeholder, starts loading image 2 asynchronously
    image 1 loading is complete, calling setImageBitmap on imageView
    painting position 3, uses image 1, starts loading image 3 asynchronously
    etc.
    

    What you can do though is keep a cache of Bitmaps in the listadapter. Something like this:

    private Bitmap[] bitmapList;
    private Bitmap bitmapPlaceholder;  
    
    private void initBitmapListWithPlaceholders(){ 
    // call this whenever the list size changes
    // you can also use a list or a map or whatever so you 
    // don't need to drop all the previously loaded bitmap whenever 
    // the list contents are modified
        int count = getListCount();
        bitmapList = new Bitmap[count];
        for(int i=0;i<count;i++){
             bitmapList[i]=bitmapPlaceholder
        }
    }
    
    private void onBitmapLoaded(int position, Bitmap bmp){
    // this is your callback when the load async is done
        bitmapList[position] = bmp;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ImageView imageView;
        TextView textView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.drink_list_row, null);
        }
    
        Drink drink = allItems.get(position);
        if (drink != null && v != null) {
            imageView = (ImageView) v.findViewById(R.id.picture);
            textView = (TextView) v.findViewById(R.id.drinkName);
            imageView.setVisibility(View.GONE);
            imageView.setImageBitmap(bitmapList[position]);
            loadImageBitmap(drink, position); // this should call onBitmapLoaded(int position, Bitmap bmp) when finished to update the bitmapList and replace the placeholder
            textView.setText(drink.getName());
    
            if (subItems != null && subItems.contains(drink)) {
                textView.setVisibility(View.VISIBLE);
                imageView.setVisibility(View.VISIBLE);
            } else {
                textView.setVisibility(View.GONE);
                imageView.setVisibility(View.GONE);
            }
        }
        return v;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview which is simply populated this way: setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, aux))
i have created listview as follows... lv = (ListView) findViewById(R.id.listview); lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, mDisplay));
I have a ListView that has a custom ArrayAdapter with a custom XML row.
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a listview with a custom arrayadapter that handles about 15 strings. The
I have a ListView that I want to use with an ArrayAdapter to add
I have a listview that's populated by rows that get their data from a
I have a ListView that is filled with items of an ArrayAdapter. Now I
I have a simple listview and listadapter setup as follows: listAdapter = new ArrayAdapter<MyDomainObject>(this,
I have a ListView that uses an ArrayAdapter. The items in the ArrayAdapter are

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.