I've created a custom View subclass with the following constructor:
public MyCustomView(Context context, AttributeSet attrs)
{
super(context, attrs);
// get custom "thingy" attribute specified in XML
int thingy = attrs.getAttributeIntValue(MY_NAMESPACE, "thingy", 0);
//rest of constructor
...
}
As can be seen, it grabs a custom "thingy" attribute from its XML attributes. This works absolutely fine, and I have had no problems so far. Why then, does Google tell you to define a custom View's XML attributes in a declare-styleable
in res/values/attrs.xml
(discussed here) and to apply them by calling context.getTheme().obtainStyledAttributes()
(discussed here)?