Reputation: 42824
What i have:: I have a imageview below for which i have attached a background drawable
<ImageView
android:id="@+id/myId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/plus" />
What I am trying to find:: How can i check programmatically, if that imageview object has background drawable attached to it
Upvotes: 0
Views: 1962
Reputation: 3568
I believe the getBackground()
method is what you want. You got down voted because this is a trivial issue.
ImageView yourImageView = findViewById(R.id.myId);
Drawable background = yourImageView.getBackground();
if(background != null)
System.out.println("View has background!");
else
System.out.println("View has no background!");
Upvotes: 2
Reputation: 1167
ImageView myimage = (ImageView) v.findViewById(R.id.img_call_icon);
myimage.setTag(R.drawable.myicon);
myimage.setBackgroundResource(R.drawable.myicon);
myimage.
Object tag = myimage.getTag();
int id = tag == null ? -1 : (int) tag;
switch (id) {
case R.drawable.icon:
Toast.makeText(mContext, "skype", Toast.LENGTH_SHORT).show();
break;
case R.drawable.myicon:
Toast.makeText(mContext, "call", Toast.LENGTH_SHORT).show();
break;
}
Upvotes: 0