Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView onImageChangedListener Android

Is there an onImageChangedListener() on a ImageView?

I need the event when the image is changed from the ImageView.

like image 461
Naskov Avatar asked Nov 29 '12 08:11

Naskov


People also ask

Which method is used to change the ImageView background programmatically?

setImageResource(0); qImageView. setImageResource(R. drawable.

What is ImageView in Android?

ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics. drawable.

How do you show the full size image in pop up when clicking the picture on android?

How to show the full size image in popup on clicking the image in android. Below is the code that will show the full size image in a dialog box popup without defining layout xml file . int a=v. getId(); intiger "a" will have the value equal to profile_pic if we touched on profile_pic imageview else we will get pro id .


2 Answers

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);
        }
    }
like image 117
Sandeep P Avatar answered Sep 26 '22 06:09

Sandeep P


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?

like image 32
e7fendy Avatar answered Sep 26 '22 06:09

e7fendy