I have a custom view (that extends viewgroup) and I have specified some custom attributes defined in attrs.xml....
<declare-styleable name="datascope">
<attr name="colcount" format="integer" />
<attr name="titleheaderrows" format="integer" />
<attr name="colheaderrows" format="integer" />
<attr name="rowlayout" format="reference" />
</declare-styleable>
The integers I can pickup fine, but the last one - rowlayout
- I want to use to refer to a further layout file that I will inflate on demand. But I cannot find the right way to express rowlayout attribute in the main layout file.
I have tried:
lui:rowlayout="@layout/sensorvaluesdata">
but this fails at runtime:
E/AndroidRuntime(22092): Caused by: java.lang.NumberFormatException: unable to parse 'res/layout/sensorvaluesdata.xml' as integer
and
lui:rowlayout="?layout/sensorvaluesdata"
which fails
E/AndroidRuntime(22341): Caused by: java.lang.NumberFormatException: unable to parse '?2130903043' as integer
Which is interesting 'cos it seems to have stuck the resource ID in there, but stuck a ?
on the front as well.
My R.java files does have a sensible looking line for sensorvaluesdata
.
public static final class layout {
public static final int sensorvaluesdata=0x7f030003;
}
what is the right way to do this?
(I can hard code the info into the java source and it works fine....
View vx = li.inflate(R.layout.sensorvaluesdata, this, false);
Just to add a little more background for someone else. In code use something like this
LinearLayout ViewContainer=(LinearLayout) (LayoutInflater.from(context)).inflate(
attributes.getResourceId(
R.styleable.[styleableName]_[attributeName],
R.layout.[defaultValue]),
null);
In xml attributes under you styleable name...
<attr name="layout" format="reference"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With