Retrieve arguments for android:entries -
i'm subclassing spinner
class, , need objects specified in xml file android:entries
. how can that?
<com.myapp.myspinner android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/myarray"/>
so need either array specified in entries
argument, or resourceid can fetch them myself.
you need override constructor of spinner
, retrieve entries attributeset
param.
public class myspinner extends spinner { public myspinner(context context, attributeset attrs) { super(context, attrs); if (attrs != null) { final int[] ids = {android.r.attr.entries}; final typedarray array = context.obtainstyledattributes(attrs, ids); final int entriesid = array.getresourceid(0, 0); if (entriesid > 0) { final resources resources = context.getresources(); final string[] entries = resources.getstringarray(entriesid); if (entries != null) { // whatever want here } } } } }
android
No comments:
Post a Comment