Edittext In Google Android
I want to create the EditText which allow Numeric Values, Comma and Delete and other values are ignore. So How I can achieve this by programming code ? Thanks.
Solution 1:
I achieved same thing using follwing code, hope you will also find help from it.
editText.addTextChangedListener(controller);
@OverridepublicvoidafterTextChanged(Editable s) {
if(s.trim.length() > 0)
{
intstart= s.toString().length() - 1;
inta= (int) s.charAt(start);
if (!(a >= 48 && a <= 57 || a == 44))
s = s.delete(start, start + 1);
}
}
@OverridepublicvoidbeforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {
}
Solution 2:
To restrict what characters can be typed into an android EditText, you must set them in the android:digits XML attribute. See http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits . Make sure to also validate user input before putting it into storage.
Solution 3:
just simple ,
you want to create a text-field like that you can enter the new string must have some grammar that you want to allow.
i have some email validation grammar that can help you.
string = "/alphabetics/number/special-character" ;
and another is
user-entered-string = " ";
just compare user-entered-string's lexems and you defined grammar.
Post a Comment for "Edittext In Google Android"