Cancel textchange listener event

I have a edittext with a textchange listener. In the listener I test if the input of the user is where I want to test if the input is within the min-max boundaries.

valueText.addTextChangedListener(new TextWatcher() {
    String backup = "0";

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (count > 0 && !s.equals(backup)) {
            if (Integer.parseInt(s.toString()) > getMaximum()) {
                valueText.setText(backup);
            }
        }
    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        backup = s.toString();
    }

    public void afterTextChanged(Editable s) {
    }
});

At the moment I have this, but is there an easy way to 'cancel' the textchange event so nothing happens when the value is above the maximum?

Or can i use a inputfilter where I can set the min and max input?

Thx :)

EDIT: I found a solution here: http://tech.chitgoks.com/2011/06/27/android-set-min-max-value-an-edittext-accepts/

Answers


You can use android:maxLength on your EditText XML definition.


 InputFilter.LengthFilter mLenthFilter=new InputFilter.LengthFilter(25); // pls define yr max length mine was 25.
        valueText.setFilters(new InputFilter[]{mLenthFilter});

http://tech.chitgoks.com/2011/06/27/android-set-min-max-value-an-edittext-accepts/, with this you can set the min and max value of an edittext.


Need Your Help

PHP - XML not parsed

php xml web-services curl fsockopen

I'm tryng to send an request to Cielo's webservice, but if i send with curl, fsockopen or other, it doesn't work, and if I post an form, it work perfectly...

Javascript popup window (minimum) height

javascript popup window

I am creating a simple popup window and the window height will not resize to 30 pixels. It always defaults to 100 pixels. This behavior appears in all browsers. Am I missing something?