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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:28:56+00:00 2026-05-21T00:28:56+00:00

I am a little bit confused about this piece of code : for(int i

  • 0

I am a little bit confused about this piece of code :

  for(int i = 0; i < poi.getCommenti().size();i++){
            item = poi.getCommenti().get(i);
            commento = li.inflate(R.layout.commento, null); 
            commento_data = (TextView) commento.findViewById(R.id.commento_data);
            commento_descrizione =(TextView)  commento.findViewById(R.id.commento_descrizione);
            commento_name = (TextView) commento.findViewById(R.id.commento_nome);
            commento_foto = (ImageView) commento.findViewById(R.id.commento_foto);
            Log.d(TAG, "commento_foto:"+commento_foto);
            commento_data.setText(item.getData());
            commento_descrizione.setText(item.getTesto());
            commento_name.setText(item.getUtente().getName());
            contenitore_commenti.addView(commento);
               image[i] = new ImageViewURL(commento_foto, item.getAnteprimaURL());  
        }

        // I start only one thread for all images
        thread_image_commenti = new ImageThreadURL(this);
        thread_image_commenti.execute(image);

thread image is a simple thread which do a download of an image and take 2 param:

1) an ImageView where thread call setImage(Bitmap)

2) an String representing an URL (for download image)

The problem is that I can see all my photo flicker when a single image is downloaded and all photo have the same image (URL are not the same).

This is the right way ? Inflate a NEW view for each element create a NEW VIEW OBJECT for each iteration or them are the same object ?

What’s wrong?

Thanks a lot in advance.

pedr0

This is the code of my thread:

public class ImageThreadURL extends AsyncTask<SingleImageURL, SingleImageURL,Void>{

    public final static String TAG = "ImageThreadURL";
    static final int MAX_CONN = 25;
    static final int TIMEOUT_DATA = 0;
    static final int TIMEOUT_CONNECTION = 10000;

    Activity caller;
    Animation animation;


    public ImageThreadURL(Activity caller) {
        super();
        this.caller = caller;
        this.animation  = AnimationUtils.loadAnimation(caller, R.anim.alphaanimation);
        animation.setRepeatCount(0);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        caller.setProgressBarIndeterminateVisibility(true);
    }

    @Override
    protected Void doInBackground(SingleImageURL... arg0) {
        Log.d(TAG, "Lunghezza array input:"+arg0.length);
        HttpParams parameters = new BasicHttpParams();
        HttpProtocolParams.setVersion(parameters, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(parameters, HTTP.UTF_8);
        HttpProtocolParams.setUseExpectContinue(parameters, false); // some webservers have problems if this is set to true
        ConnManagerParams.setMaxTotalConnections(parameters, MAX_CONN);
        HttpConnectionParams.setConnectionTimeout(parameters, TIMEOUT_CONNECTION);
        HttpConnectionParams.setSoTimeout(parameters,TIMEOUT_DATA);
        SchemeRegistry schReg = new SchemeRegistry();
        schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        ClientConnectionManager conMgr = new ThreadSafeClientConnManager(parameters,schReg);
        DefaultHttpClient client_http = new DefaultHttpClient(conMgr, parameters);
        HttpGet method;
        HttpResponse response;
        HttpEntity entity;
        InputStream in ;
        Bitmap image ;

        SingleImageURL actual=null;

        try{
            for(int i = 0; i < arg0.length ;i++){   
                actual = arg0[i];
                Log.d(TAG,"Preparo download:"+ actual.getUrl());
                if(actual.getUrl() == null)
                    continue;
                method = new HttpGet(Uri.decode(actual.getUrl()));
                response = client_http.execute(method); 
                entity = response.getEntity();
                BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); 
                in = bufHttpEntity.getContent(); 
                image = BitmapFactory.decodeStream(in);
                // problema scaricamento immagine
                if(image == null){throw new Exception("BitmapFactory.decodeStream() return null!");}
                else{       
                    Log.d(TAG,"Eseguito Download:"+ actual.getUrl());
                    actual.setImage(image);
                    publishProgress(arg0[i]);
                }
            }

        }catch (Exception e) {e.printStackTrace();}
        return null;
    }

    @Override
    protected void onProgressUpdate(SingleImageURL... values) {
        Log.d(TAG, "onProgressUpdate");
        values[0].getView().startAnimation(animation);
        values[0].setImage();
    }


    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        caller.setProgressBarIndeterminateVisibility(false);
    }



}
  • 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-21T00:28:57+00:00Added an answer on May 21, 2026 at 12:28 am

    You should also post the Thread code. In Android, you cannot alter UI objects (ImageView) from another thread than the UI thread. This might be what is happening.

    If you have multiple views, you should consider using the ListView widget along with a custom adapter (to inflate the layout for each row).


    Edit:

    1. Have you tried to get rid of the animations at first time to see if the problem remains?

    2. I also noticed that you are creating two ImageViewURL objects.

          image[i] = new ImageViewURL(commento_foto, item.getAnteprimaURL());
          thread_image_commenti = new ImageThreadURL(this);
          thread_image_commenti.execute(new ImageViewURL(commento_foto, item.getAnteprimaURL()));
      

    Shouldn’t that be:

            image[i] = new ImageViewURL(commento_foto, item.getAnteprimaURL());
            new ImageThreadURL(this).execute(image[i]);
    

    ?

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

Sidebar

Related Questions

I am little bit confused about this statement that I read in a book
I'm a little bit confused about how to approach this. I had never used
I'm a little bit confused about this expression: char *s = abc; Does the
I'm a little bit confused about how to get an index of a selected
I am a little bit confused about 2 things. Firstly when I create an
I am little bit confused about following problem & their solutions: i have 2
Started learning Wicket after ASP.NET MVC and feel a little bit confused about managing
I´m a little bit confused by reading all the posts and tutorials about starting
I'm using SQLite as my database, and I'm a little bit confused about how
Ok. Im little bit confused about those permissions in linux so please people help

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.