thest1 / LazyList

Lazy load of images in Android
http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012
MIT License
1.2k stars 497 forks source link

[Question] Callback for finished load image? #29

Open VAdaihiep opened 11 years ago

VAdaihiep commented 11 years ago

Hi Fedor, Thank for your project, it's simple but awesome. I have small question that: How can I show a Toast or do somethings else when finished load image from internet or cache?

jovisayhehe commented 11 years ago
public class ImageLoader{   
    //xxx

    ImgLoadListener loadListener;

    //xxx
    //Used to display bitmap in the UI thread
    class BitmapDisplayer implements Runnable
    {
    //xxx
            if(bitmap!=null){
                loadListener.onFinished();
                photoToLoad.imageView.setImageBitmap(bitmap);
            }
       //xxx
    }

    public void setImgLoadListenerListener(ImgLoadListener load){
        this.loadListener  = load;
    }

    public interface ImgLoadListener {
     public void onFinished() ;
   }

}

//LazyAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.item, null);

    TextView text=(TextView)vi.findViewById(R.id.text);;
    ImageView image=(ImageView)vi.findViewById(R.id.image);
    text.setText("item "+position);
    imageLoader.DisplayImage(data[position], image);
    imageLoader.setImgLoadListenerListener(new ImgLoadListener() {
        @Override
        public void onFinished() {
            // TODO Auto-generated method stub
            Toast.makeText(activity, "finsh", Toast.LENGTH_SHORT).show();
        }
    });
    return vi;
}