Issue
So I've got a custom view with this attribute:
private var mLabelText: String = "DEFAULT"
var labelText: String
set(value) {
if (mLabelText != value) {
mLabelText = value
invalidate()
}
}
get() { return mLabelText }
And defined in attr.xml
as
<declare-styleable name="CustomView">
<attr name="labelText" format="string"/>
</declare-styleable>
Now if I try to do this in my layout XML to set the value, it doesnt work (the text still shows 'DEFAULT')
<CustomView
...
app:text="NewText" />
However, if I do this, it works:
<CustomView
...
app:text="@{`NewText`}" />
So what gives?
How come views like TextView
allow me to do android:text="Text"
instead of having to write android:text="@{`Text`}
, but my own custom view wont?
Solution
Mike's comments answer the confusion I had about the different syntaxes.
What I ended up doing ultimately is to inherit the existing android TextView. TextView has a bunch of stuff I needed like font, font size etc, so it was just simpler to inherit rather than re-implement it myself.
Answered By - Olli
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.