android - Set inner edittext xml properties on custom view -
i created compound view consisting on edittext , textview... want make developer using view able following
<mycustomview android:id="@+id/password" android:layout_width="wrap_content" android:layout_height="wrap_content" app:setinputtype="textpassword"/> pay close attention last line of xml. how can wire property edittext lives inside mycustomview
pd: created on attrs.xml , tried this
<declare-styleable name="validateedittext"> <flag name="none" value="0x00000000" /> <flag name="text" value="0x00000001" /> <flag name="textcapcharacters" value="0x00001000" /> <flag name="textcapwords" value="0x00002000" /> <flag name="textcapsentences" value="0x00004000" /> <flag name="textautocorrect" value="0x00008000" /> ... this not work.. edittext.setcontenttype not working reason
i alredy set other custom attributes, question how set particular 1 "inputtype" doesnt seem working.
protected void init(context context, attributeset attrs) { if (attrs != null) { typedarray typedarray; typedarray = context.obtainstyledattributes(attrs, r.styleable.validateedittext); try { mhint = typedarray.getstring(r.styleable.validateedittext_hint); minputtype = typedarray.getint(r.styleable.validateedittext_inputtype, editorinfo.type_class_text); mmaxlength = typedarray.getint(r.styleable.validateedittext_maxlength, -1); msingleline = typedarray.getboolean(r.styleable.validateedittext_singleline, false); mpassword = typedarray.getboolean(r.styleable.validateedittext_password, false); mimeoption = typedarray.getint(r.styleable.validateedittext_imeoptions, editorinfo.ime_action_next); meditable = typedarray.getboolean(r.styleable.validateedittext_editable, true); } catch (exception e) { e.printstacktrace(); } { typedarray.recycle(); } } } @override protected void onfinishinflate() { super.onfinishinflate(); //initialise views merrormessage = (textview) findviewbyid(r.id.error_msg); medittext = (edittext) findviewbyid(r.id.edit_text); medittext.setinputtype(minputtype); ... }
you can declare styleable attr this:
<declare-styleable name="mycustomview"> <attr name="android:inputtype"/> </declare-styleable> and attr in custom view this:
int inputtype = a.getint(r.styleable.mycustomview_android_inputtype, editorinfo.type_null); you can more detail answer here
Comments
Post a Comment