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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:23:14+00:00 2026-06-18T07:23:14+00:00

For some reason my custom adapter is only allowing me to have 1 image

  • 0

For some reason my custom adapter is only allowing me to have 1 image visible in the list view at any time, I am not sure why this is happening. There should be a image within each list item but only the last list item has its image set, so I assume I am re-using a value somewhere that I should not be. The rest of the list items are being set properly.

public class CustomAdapter extends ArrayAdapter<Item> {

    private ArrayList<Item> itemList;
    private ViewHolder holder; 
    private Context context;

    public CustomAdapter(Context context, int textViewResourceId, ArrayList<Item> list) {
        super(context, textViewResourceId, list);
        this.itemList = new ArrayList<Item>();
        this.itemList.addAll(list);
        this.context = context;
    }

    private class ViewHolder {
        ImageView img;
        TextView name;
        CheckBox access;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(R.layout.list_grid, null);

            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.access = (CheckBox) convertView.findViewById(R.id.checkBox1);
            holder.img = (ImageView) convertView.findViewById(R.id.imageView1);

            convertView.setTag(holder);
        } 

        else { holder = (ViewHolder) convertView.getTag(); }

        Item it = itemList.get(position);

        new UrlLookup().execute(it.getUrl());
        holder.name.setText(it.getName());
        holder.access.setChecked(it.isSelected());

        return convertView;
    }

    //Create an image from the url passed in from the server and display it on the image view   
    private class UrlLookup extends AsyncTask<String, Integer, String>{
        Bitmap bmp;

        @Override
        protected String doInBackground(String... params){  
            try {
                URL u = new URL(params[0]);
                bmp = BitmapFactory.decodeStream(u.openConnection().getInputStream());
            } catch (Exception e) { e.printStackTrace(); }

            return "Done!";
        }

        @Override
        protected void onPostExecute(String result){
            super.onPostExecute(result);    
            holder.img.setImageBitmap(bmp);
        }
    }
}
  • 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-06-18T07:23:15+00:00Added an answer on June 18, 2026 at 7:23 am

    You’re forgetting the fact that your holder changes every time a view is visible. So it’s normal only the last item has an image.

    AsyncTask will take considerably longer to finish than your getView method.

    You should pass your ImageView to your AsyncTask:

    new UrlLookup().execute(it.getUrl(), holder.img);
    

    To call the AsyncTask

    private class UrlLookup extends AsyncTask<Object, Integer, String>{
        Bitmap bmp;
        ImageView view;
    
        @Override
        protected String doInBackground(Object... params){ 
            view = (ImageView) params[1]; 
            try {
                URL u = new URL((String)params[0]);
                bmp = BitmapFactory.decodeStream(u.openConnection().getInputStream());
            } catch (Exception e) { e.printStackTrace(); }
    
            return "Done!";
        }
    
        @Override
        protected void onPostExecute(String result){
            super.onPostExecute(result);    
            view.setImageBitmap(bmp);
        }
    }
    

    Now you will have a reference of the ImageView of every row in every AsyncTask.

    I would like to point out to you that Koush has a splendid project for doing just what you want:
    UrlImageViewHelper

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

Sidebar

Related Questions

i have a list view and custom list adapter for it. There are various
With this configuration for some reason Conver function of Custom Converter is not called
I have the following HorizontalScrollView with 2 custom views. For some reason it doesn't
I have made a custom loop in WordPress and for some reason, the date
My listener is not getting called for some reason? This is what I have:
I have a ListView with a custom view rendered by an adapter. It contains
For some reason my custom variables are not showing up in my Google Analytics
I have several custom components in my uses list of a unit. For some
I have a global post query running, but for some reason my custom meta
I have created a custom jQuery plugin that does some simple image resizing for

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.