Hi I\'m a newbie in Android Programming.
I\'m trying to build an activity which includes an edittext
field and a button
. When user type in an
Try this solution.
You need to add the properties android:nextFocusDown="@+id/nextedittext_id"
and
android:singleLine="true"
in your edittexts.
For example:
And add the following code in your activity:
editText1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String value=s.toString();
if(isNumeric(value)){
if(Integer.parseInt(value)>=100){
editText1.setFocusableInTouchMode(true);
editText1.setFocusable(false);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
editText2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
editText1.setFocusableInTouchMode(true);
editText1.setFocusable(true);
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
isNumeric method is as same as above:
public static boolean isNumeric(String str)
{
return str.matches("-?\\d+(.\\d+)?");
}