java - How to set Min text(Mandatory) and Max text in edittext -


in edit text box,i want give min text mandatory , max text having limitation want give in edittext box,is way there give in edittext value.

if type text count of numeric has decrease that.how one.

<edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/textview1" android:layout_margintop="24dp" android:maxlength="175" android:ems="10" /> 

this adding activity.java

@override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.home_layout);         system.out.println(prayer_category.length);         tvprayer = (textview) findviewbyid(r.id.mystate);         spinnerprayers = (spinner) findviewbyid(r.id.spinnerstate);          arrayadapter<string> adapter_state = new arrayadapter<string>(this,                 android.r.layout.simple_spinner_item, prayer_category);         adapter_state                 .setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);         spinnerprayers.setadapter(adapter_state);          value=(edittext)findviewbyid(r.id.edittext1);         value         .setonfocuschangelistener(new view.onfocuschangelistener() {             @override             public void onfocuschange(view v, boolean hasfocus) {                 // todo auto-generated method stub                  if (hasfocus) {                if (value.gettext().tostring().trim()                             .length() < 3) {                     value.seterror("failed");                         } else {                             value.seterror(null);                         }                     }                  else {                     if (value.gettext().tostring().trim()                             .length() < 3) {                          value.seterror("failed");                         } else {                             value.seterror(null);                         }                     }                 }           });         btnspeakprayer = (imagebutton) findviewbyid(r.id.btnspeakprayer);         btn=(button)findviewbyid(r.id.button1);         pb=(progressbar)findviewbyid(r.id.progressbar1);         pb.setvisibility(view.gone);         btn.setonclicklistener(this); 

or can change code

value.setonfocuschangelistener(new view.onfocuschangelistener() {         @override         public void onfocuschange(view v, boolean hasfocus) {             // todo auto-generated method stub              if (hasfocus) {            if (value.gettext().tostring().trim()     **try using value.gettext().length()<3**                         .length() < 3) {             **instead of value.gettext().trim().length()**                 value.seterror("failed");                     } else {                         value.seterror(null);                     }}}}); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -