Hello guys, back again with me. Well this time I want to share a case when I want to check the imageView source which I will later check or compare with several image sources that I have prepared, but at that time I experienced several failures when trying to print it to the Android Studio console / terminal.
Long story short, I managed to do it, so this is what it looks like.
if (regProfile.getDrawable().getConstantState() == getResources().getDrawable(R.drawable.ivpic).getConstantState())
{
Toast.makeText(_con, "Image is ivPic", Toast.LENGTH_LONG).show();
// new RegisterAsyntaskNew().execute();
}
else
{
Toast.makeText(_con, "Image isn't ivPic", Toast.LENGTH_LONG).show();
// new RegisterAsyntask().execute();
}
In essence, we need to use .getConstantState(), you can read the full documentation about this method here:
- http://developer.android.com/reference/android/graphics/drawable/Drawable.html
- http://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState.html
Before you check the imageView, make sure that it is not null, it's as simple as this.
if(getResources().getDrawable(R.drawable.ivpic) == null){
//lakukan exeption, jika perlu!
}else{
//lakukan comparasi / pengecekan imageView di sini!
}
Hope it's useful, good luck!