Issue
I'm implementing my own <declare-styleable>
for a custom View (following the instructions here). I'd like to be able to specify an array of integers as one of the possible XML attributes. How do I:
- Specify the integer array as an XML attribute in
attrs.xml
? - Get it from the TypedArray after calling
obtainStyledAttributes()
in my custom View?
Solution
You can declare it as a reference.
<declare-styleable name="MyView"> <attr name="array" format="reference"/> </declare-styleable>
It looks like
TypeArray
hasn'tgetIntArray
method so you have to get it directly from the resources.final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MyView); final int id = array.getResourceId(R.styleable.MyView_array, 0); if (id != 0) { final int[] values = getResources().getIntArray(id); } array.recycle()
Answered By - Vladimir Mironov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.