Reputation: 13
I have a problem like this
in ImageView
, by default I set ivImage.setImageResource(R.drawable.avatar)
And when I click button "Save", if image in ImageView
is not changed, it should not save image. I tried this, but it's not working
private Drawable oldDrawable;
in onCreate()
oldDrawable = imgAvatarDoctor.getDrawable();
and in button click
if (imgAvatarDoctor.getDrawable() == oldDrawable) {
isNoError = false;
}
So how can i fix that? thanks so much
Upvotes: 0
Views: 1705
Reputation: 5550
you can use bitmap instead,
private Bitmap oldDrawable;
oldDrawable = ((BitmapDrawable) ivImage.getDrawable()).getBitmap();
if (oldDrawable == oldDrawable) {
isNoError = false;
}
Upvotes: 2
Reputation: 1121
While setting the image, set any tag to the image
image.setTag(res); //here, res is drawableID
While checking the ID of image, you can use this tag to compare:
int oldImage = image.getTag(); //oldImage will be same as drawable ID
Now you can compare oldImage with drawable ID of that image and check whether its updated or not.
Upvotes: 0
Reputation: 2535
Use setTag and getTag for comparison of your drawable like this:
initially set tag of your imageview to 0 in your onCreate
imgAvatarDoctor.setTag("0");
and whenever you change the imageview you can change the tag for something other than 0 like:
imgAvatarDoctor.setTag("UpdatedTag");
Now on your click listener you can do this:
if (imgAvatarDoctor.getTag().equalsIgnoreCase("UpdatedTag")){
//your image view is updated
} else {
// your image view is not update
}
Happy Coding !!!!!
Upvotes: 5
Reputation: 291
You can use a flag to trigger image change. In onCreate()
imageChanged = false;
And in function which gets changed image(i.e. onActivityResult), update this flag as
imageChanged = true;
then on save button click you can easily check for this flag :
if(imageChanged)
//save image
else
//pass
Upvotes: 2