1

Upon checking the android documentation for obtainstyledattributes(), I found the following:

TypedArray obtainStyledAttributes (AttributeSet set, 
                int[] attrs, 
                int defStyleAttr, 
                int defStyleRes)

Now my problem is what exactly is attrs used for in this method? According to the android documentation the attrs are for "The desired attributes to be retrieved." However, this make no sense to me.

What does an int array have to do with retrieval of the desired attributes?

If I want to get the desired attribute shouldn't I be passing in just a single integer instead of an array of integer?

Wowzer
  • 1,103
  • 2
  • 12
  • 26
  • As a follow-up to our previous discussion, `int [] attrs = { R.attr.value1, R.attr.value2 }`, for example. – OneCricketeer Dec 13 '16 at 20:35
  • Have you not checked [this](http://stackoverflow.com/questions/2127177/how-do-i-use-obtainstyledattributesint-with-internal-themes-of-android) for custom themes in a xml layout? – t0mm13b Dec 13 '16 at 20:35
  • Some examples might help http://stackoverflow.com/questions/2127177/how-do-i-use-obtainstyledattributesint-with-internal-themes-of-android – MikeSchem Dec 13 '16 at 20:36
  • Hey thanks for the response. I do realized that int[] attrs = { R.attr.value1, R.attr.value2 } but I am not so sure what exactly does all that value even do and why is it necessary? Because I can just pass in an array with int[] attrs = {0,1} and everything will work. – Wowzer Dec 13 '16 at 20:38
  • See this [code](https://github.com/android/platform_development/blob/master/samples/ApiDemos/res/values/attrs.xml#L24) that I referenced in the link above, that's why. Look at the declarative for styling, it can have many attributes, its part of a custom theming. – t0mm13b Dec 13 '16 at 20:42
  • I do understand that R.attr.value1 or R.attr.value2 is part of an index of a declarative style but why should I passed those things in? it is nothing more than integer of 0 and integer 1. Plus, the attributeset already contain all of the custom tag info. Therefore, I don't see the need for int[] attrs – Wowzer Dec 13 '16 at 20:47

0 Answers0