Android's AttributeSet.getAttributeIntValue takes String namespace as input. Hard coding the namespace seems like a bad idea, because if the namespace changes, then a runtime bug is introduced. More concretely, it would be nice to avoid
attrs.getAttributeIntValue("http://schemas.android.com/apk/res-auto",
"myAttribute", 0)
since it hard codes string "http://schemas.android.com/apk/res-auto", which seems unnecessary. (Admittedly, it hard codes "myAttribute", but that seems unavoidable.) Is it possible to read the integer attribute "myAttribute" without hard coding the name space? (Possibly by naming the xml file that contains "myAttribute".) Such that compilation errors are generated if anything goes wrong. (E.g., the file no longer exists.) Alternatively, is it possible to produce a compiler error if "myAttribute" cannot be found (this would eliminate the need for a default value too, since it would never be used).
Context. I have extended a LinearLayout to override constructors LinearLayout(Context context, AttributeSet attrs) and LinearLayout(Context context, AttributeSet attrs, int defStyleAttr). These constructors use AttributeSet.getAttributeIntValue to read attributes from attrs. Thus, code and GUI are completely separate. However, if the namespace is changed in the GUI, then problems arise when the namespace is hardcoded in the code. (This actually happened. So, I'm trying to figure out how to avoid it happening again!)
AttributeSetwhere you should useTypedValueTypedValueis relevant to me...AttributeSet attrstaken as input by the constructor, how can I recover a particular integer attribute usingTypedValueorTypedArray? At present, I simply useattrs.getAttributeIntValue("http://schemas.android.com/apk/res-auto", "myAttribute", 0), where the first parameter is the name space, the second is the name of the attribute, and the third is the default. (This is undesirable, as per my question, because I hard code the namespace.)