ImageView onImageChangedListener Android

Check the imageview code in grepcode. You don't know when it is changed or redrawn. It is because after you setImageDrawable(), imageview will invalidate. At this time, the image IS NOT CHANGED correctly until ondraw is called.

Anyway, why do you want to know the onimagechangedlistener?


If you want to load the image from network and check change in imageview you can use imageView.isAttachedToWindow(). I have tried downloading the image from network and disabled the progressbar after image downloaded and attached to window. Use,

         if(imageView.isAttachedToWindow()){ 
            //your code here
          }

There is no default listener in Android .. but we can create the imagechange listiner .. copy the class and instead of using ImageView use MyImageView..

 public class MyImageView extends ImageView {

        private OnImageChangeListiner onImageChangeListiner;


        public MyImageView(Context context) {
            super(context);
        }

        public MyImageView(Context context, AttributeSet attributeSet) {         
            super(context, attributeSet); 
        }


        public void setImageChangeListiner(
                OnImageChangeListiner onImageChangeListiner) {
            this.onImageChangeListiner = onImageChangeListiner;
        }

        @Override
        public void setBackgroundResource(int resid) {
            super.setBackgroundResource(resid);
            if (onImageChangeListiner != null)
                onImageChangeListiner.imageChangedinView(this);
        }


        @Override
        public void setBackgroundDrawable(Drawable background) {
            super.setBackgroundDrawable(background);
            if (onImageChangeListiner != null)
                onImageChangeListiner.imageChangedinView(this);
        }


        public static interface OnImageChangeListiner {
            public void imageChangedinView(ImageView mImageView);
        }
    }