android - Suppressing Keyboard popup for a single Edittext -


long story short, have date picker dialog pops on click edittext attribute. working fine, except when dialog pops soft keyboard.
not want disable keyboard other attributes on page, , not want leave is, because not sloppy , clunky, means user can mess lovely formatted date object goes nicely in database. not good.

i've tried disabling element in xml file both clickable , editable, no avail. code below, usual.

<edittext     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/edittextexpirydate"     android:inputtype="date"     android:hint="card expiry date"     android:editable="false"     android:clickable="false"     android:layout_below="@+id/edittextsecuritycode"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_alignright="@+id/spinnercardtype"     android:layout_alignend="@+id/spinnercardtype" /> 

and (somewhat messy) java file, relevant parts in bold.

public class registerfragmentpaymentinfo extends fragment {  public spinner creditcardspinner; public edittext cardnumberinput; **public edittext expirydateinput;** public edittext securitycodeinput; public button proceedbutton;  public string cardtype; public string cardnumber; **public date expirydate;** public int securitycode;  bundle olduserdata; calendar c = calendar.getinstance();   **datepickerdialog.ondatesetlistener date = new datepickerdialog.ondatesetlistener() {     @override     public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) {         c.set(calendar.year, year);         c.set(calendar.month, monthofyear);         c.set(calendar.day_of_month, dayofmonth);         updatedateinput();     } }; private void updatedateinput(){     simpledateformat sdf = new simpledateformat("dd/mmm/yy");     expirydateinput.settext(sdf.format(c.gettime())); }**  @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     super.oncreateview(inflater, container, savedinstancestate);     view rootview = inflater.inflate(r.layout.fragment_register_payment_info, container, false);      findinputfields(rootview);      arrayadapter<charsequence> = arrayadapter.createfromresource(this.getactivity(), r.array.credit_card_array, android.r.layout.simple_spinner_item);     a.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);      creditcardspinner.setadapter(a);     creditcardspinner.setprompt("please select card type");      proceedbutton.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             readuserinput();              if (isvalidinput()) {                 bundle userdata;                 userdata = preparedatatopass(olduserdata);                  registerfragmentconfirm targetfragment = new registerfragmentconfirm();                 targetfragment.setarguments(userdata);                 fragmenttransaction t = getfragmentmanager().begintransaction();                 t.replace(r.id.fragment_login_main, targetfragment);                 t.addtobackstack(null);                 t.commit();              }          }     });        e**xpirydateinput.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             new datepickerdialog(getactivity(), date, c.get(calendar.year), c.get(calendar.month), c.get(calendar.day_of_month)).show();         }     });**       return rootview; }  public void findinputfields(view tempview){     creditcardspinner = (spinner) tempview.findviewbyid(r.id.spinnercardtype);     cardnumberinput = (edittext)tempview.findviewbyid(r.id.edittextcardnumber);     expirydateinput = (edittext)tempview.findviewbyid(r.id.edittextexpirydate);     securitycodeinput = (edittext) tempview.findviewbyid(r.id.edittextsecuritycode);     proceedbutton = (button) tempview.findviewbyid(r.id.btncompleteregistrationstepthree);      expirydateinput.setfocusable(false); }  public void readuserinput(){     cardtype = creditcardspinner.getselecteditem().tostring();     cardnumber = cardnumberinput.gettext().tostring();      try{         if(securitycodeinput.gettext().tostring()!=null){             if(securitycodeinput.gettext().tostring().length()==3||securitycodeinput.gettext().tostring().length()==4){                 securitycode = integer.parseint(securitycodeinput.gettext().tostring());             }             else {                 toast.maketext(getactivity(), "security number invalid, please enter valid security number", toast.length_long).show();             }         }else{             toast.maketext(getactivity(), "security number mandatory, please enter security number", toast.length_long).show();         }     }catch (numberformatexception e){         toast.maketext(getactivity(), "security number must numeric, please enter valid security number", toast.length_long).show();     }      simpledateformat s = new simpledateformat("dd/mmm/yy");     try {         expirydate = s.parse(expirydateinput.gettext().tostring());     } catch (parseexception e) {         e.printstacktrace();     } } public boolean isvalidinput(){     boolean inputisvalid = false;      //boolean validcardtype; //unnecessary; user cannot select other supplied card types     boolean validcardnumber = false;     boolean validexpirydate;     //boolean validsecuritycode; //also unnecessary, validated upon initial input simplicity.     date currentdate = new date();     string dateintermediate;     calendar c = calendar.getinstance();      if (!cardnumber.isempty()){         validcardnumber = true;     }else if(cardnumber.isempty()){         validcardnumber = false;         toast.maketext(getactivity(), "card number mandatory, please enter card number", toast.length_long).show();     }      simpledateformat s = new simpledateformat("dd/mmm/yy");     dateintermediate = s.format(c.gettime());     try {         currentdate = s.parse(dateintermediate);     } catch (parseexception e) {         e.printstacktrace();     }       if(expirydate.after(currentdate)){         validexpirydate =true;     }     else{         validexpirydate = false;         toast.maketext(getactivity(), "card has expired, please use card within date, or check given expiration correct", toast.length_long).show();     }      if(validexpirydate&&validcardnumber){         inputisvalid = true;     }      return inputisvalid; }  public bundle preparedatatopass(bundle previoususerdata){     bundle newbundle = new bundle();     newbundle.putall(previoususerdata);      newbundle.putstring("card_type", cardtype);     newbundle.putstring("card_number", cardnumber);     newbundle.putserializable("expiry_date", expirydate);     newbundle.putint("security_code", securitycode);      return newbundle; } 

}

public void setfocusable (boolean focusable)

set whether view can receive focus. setting false ensure view not focusable in touch mode.

so, when set focusable false edittext. can still detect click event not open keyboard it's not able acquire focus.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -