java - How to get locale of string on android? -


i want know locale of input text in edittext! tried keyboard locale wasn't helpful. don't want type english in edittext me! want user know he/she can't type english!

sorry bad english!

here code :

  edtusernamelogin.addtextchangedlistener(new textwatcher() {         @override         public void beforetextchanged(charsequence charsequence, int i, int i1, int i2) {         }          @override         public void ontextchanged(charsequence charsequence, int i, int i1, int i2) {         }          @override         public void aftertextchanged(editable editable) {             if (editable.tostring().isempty()) {                 mtfusernamelogin.setlabelcolor(g.resources.getcolor(r.color.cpb_white), "نام کاربری");             } else {                 string locale = g.inputmethodmanager.getcurrentinputmethodsubtype().getlocale();                 if (locale.equals("fa") || locale.equals("ar")) {                     mtfusernamelogin.setlabelcolor(g.resources.getcolor(r.color.spink), "نام کاربری باید انگلیسی باشد !");                 } else {                     mtfusernamelogin.setlabelcolor(g.resources.getcolor(r.color.sgreen), "نام کاربری");                 }             }         }     }); 

the solution :

inputfilter usernamefilter = new inputfilter() {         @override         public charsequence filter(charsequence source, int start, int end, spanned dest, int dstart, int dend) {             string blockcharacterset = " اآبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی";             if (blockcharacterset.contains(source)) {                 edtnameedit.sethinttextcolor(getresources().getcolor(r.color.grey));                 edtnameedit.sethint("نام و نام خانوادگی");                 return source.tostring();             } else {                 edtnameedit.sethinttextcolor(getresources().getcolor(r.color.spink));                 edtnameedit.sethint("نام و نام خانوادگی باید فارسی باشد!");                 return "";             }         }     };     edtnameedit.setfilters(new inputfilter[]{usernamefilter}); 

and important line :

    edtnameedit.setinputtype(inputtype.type_text_flag_no_suggestions); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -