4
    final Handler downloadHandler =  new Handler() {
        public void handleMessage(Message msg) {
            Log.d("Yoon", "Handler");
            MCImageDisposableView iconView = new MCImageDisposableView(profileSprite, tag);
            iconView.setScale(0.5f);
            iconView.setPosition(17, 145);
            addActor(iconView);
        }
    };

    Thread sb = new Thread(new Runnable() {
        @Override
        public void run() {
            Log.d("Yoon", "Thread");
            profileSprite = BitmapDownloader.downloadSprite(Utils.getImageURL(MyChoiceApp.shared.context, aid));
            downloadHandler.sendEmptyMessage(0);
        }
    });

    sb.start();

If use thread without handler, change actor(MCImageDisposableView has sprite) image.

But image is not correct. image is not loaded my url. image is loaded texture atlas

MCImageDisposableView class have donwload image function. It works good... if not use thread.

How can I load asynchronous image ?

ChangUZ
  • 5,380
  • 10
  • 46
  • 64
  • What do u want to achieve in your application. Please tell me the exact scenario. – AndoAiron Jul 03 '12 at 11:43
  • @AndoAiron I want to add actor(url image) to parent actor. Using main thread(While construct parent actor, add url image actor) works fine via wifi... but slow via 3G. So I want to download and add url image actor after construct parent actor... – ChangUZ Jul 04 '12 at 01:17

2 Answers2

1

You need to implement lazyloading for this.

Read the below mentioned link for lazyloading :

Lazy load of images in ListView

Here is the basic idea for doing this :

addActor(){
   //if you need to download image from url
   downloadImageFromUrl(actorImageView, url);
}

downloadIamgeFromUrl(ImageView actorImageView, String url){
    //ToDo : create Thread to download image from server
    //ToDo : Once done, set this image to actorImageView  in UI thread as
    //runOnUiThread(new Runnable() {
        @Override
        public void run() {
            actorImageView  .setImageBitmap(bitmap);
        }
    });
}
Community
  • 1
  • 1
AndoAiron
  • 694
  • 5
  • 19
  • It doesn't work! As @ChangUZ said the image is not correct if use loading in background thread. – Nolesh Mar 21 '13 at 22:11
1

I have created MyLazyImageList for this purpose. It's based on ScrollPane. Now it looks like below:

enter image description here

You can modify the code if you need. So the source code is here: http://pastebin.com/JPWTB9PF or here: http://pastebin.com/hi0v0nQy

Nolesh
  • 6,848
  • 12
  • 75
  • 112