Ant4res
Ant4res

Reputation: 1225

How to get textview drawable resource id

I have an UI with some TextViews and I want to test if a textView has a certain drawable resource as background. I'm using the following code, but the tag is always null.

Object tag = textView.getTag();
int backgroundId = R.drawable.bg_image_2;
if( tag != null && ((Integer)tag).intValue() == backgroundId) {
   //...do something...
}else{
   //...do something...
}

Which method returns the R.drawable background id number of an object? What am I doing wrong?

Upvotes: 0

Views: 1330

Answers (2)

TieDad
TieDad

Reputation: 9899

Tag is a feature for developer to save some object with Widget, you have use setTag() to save an arbitary object with UI widget. If you didn't setTag(), then getTag() would return NULL.

Upvotes: 1

VinceFR
VinceFR

Reputation: 2571

If the tag is null, it's because you didn't affect an Object to it with setTag

Upvotes: 1

Related Questions