Tyler
Tyler

Reputation: 19878

Finding the value of the reference name to R

I am doing some debugging in my application, mainly loading custom styles from styles.xml when my custom view is given a style="@styles/CustomStyle", and attributes such as custom:attribute="custom value"

I looked into the TextView source to see how Android loads styles/attributes and I am mimicking that. However I am not being passed any of my R.styleables through some of the calls to my constructors and so I am trying to peek in there to see which resources are coming in.

I am using obtainStyledAttributes() to load these key/value pairs into a TypedArray, however I am wondering if there is an easy way to convert the R.styleable.CustomWidget_customAttribute from the int that R reads, to its referenced name.

In essence, I want LogCat to say, "We've been given R.styleable.xxx" and not "We've been given 1487214712442"

Upvotes: 1

Views: 114

Answers (2)

pawelzieba
pawelzieba

Reputation: 16082

Look at this method: http://developer.android.com/reference/android/content/res/Resources.html#getResourceName(int)

Return the full name for a given resource identifier. This name is a single string of the form "package:type/entry".

Upvotes: 2

Codeman
Codeman

Reputation: 12375

You most likely are not able to do this explicitly, as all resources are stored in a generated java class with no accessible reference to the original strings.

However, your best bet is override the toString() method for the R class.

See if something like that works.

Hope this helped!

Upvotes: 0

Related Questions