I want the user cannot enter greater than value 15. If the user enters the value 1 and then enter 6 that time 6 must not be entered. Only below 15 values can enter a user.
Asked
Active
Viewed 95 times
0
-
3http://stackoverflow.com/questions/14212518/is-there-a-way-to-define-a-min-and-max-value-for-edittext-in-android – Rak Dec 19 '16 at 11:51
-
http://stackoverflow.com/questions/14212518/is-there-a-way-to-define-a-min-and-max-value-for-edittext-in-android – Arjun Dec 19 '16 at 11:52
1 Answers
1
Use this code in XML to allow numbers only in Edit Text:
<EditText android:id="@+id/edit_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numbers" />
To control the text values entered in that EditText:
edittext.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count){
String strEnteredVal = edittext.getText().toString();
if(!strEnteredVal.equals("")){
int num=Integer.parseInt(strEnteredVal);
if(num<16){
edittext.setText(""+num);
}else{
edittext.setText("");
}
}
});

Suresh Kumar S
- 182
- 12