I have an ImageView
and I am setting different image based on different condition like this way-
if(x==1){
image.setImageResource(bitMapIdOne);
}else {
image.setImageResource(bitMapIdTwo);
}
Now I want to get the id
of Bitmap
from this ImageView
. I want to get id
like this way image.getId()
that will return currently set Bitmap id. Suppose that current id is bitMapIdOne
and it will return bitMapIdOne
for me.
Is it possible or how do I get Bitmap
id?
a bitmap does not have id. You are needed to use setImageBitmap instead of setImageResource
You can the ImageView's drawable, the app's drawables and find out which one is it by comparison:
if (image.getDrawable().getConstantState().equals(
getResources().getDrawable(R.drawable.image1).getConstantState())) {
} else if (image.getDrawable().getConstantState().equals(
getResources().getDrawable(R.drawable.image2).getConstantState()) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.