I have an edittext in which I have to enter only digits below 10000. 9999.99 is a valid entry but 10000 is not. Is there any way to limit the number of digits in the mantessa part
Asked
Active
Viewed 643 times
0
-
http://stackoverflow.com/questions/4769577/how-can-i-limit-the-edittext-box-input-to-two-characters-after-a-decimal-place – run Sep 27 '11 at 11:33
2 Answers
0
add this line android:numeric="integer"
and take a TextWatcher check total value< 10000
<EditText android:numeric="integer"... />
edittext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
float final =Float.valueOf(s.toString());
if(final<10000)
//accept
else
//reject
}
});

jazz
- 1,216
- 7
- 7
0
You can use InputFilter in your edittext:
http://developer.android.com/reference/android/text/InputFilter.html

Rodrigo
- 5,435
- 5
- 42
- 78