create Numeric Input Filter - Android android.text

Android examples for android.text:InputFilter

Description

create Numeric Input Filter

Demo Code


//package com.java2s;

import android.text.InputFilter;
import android.text.Spanned;

public class Main {

    public static InputFilter[] createNumericInputFilter() {
        InputFilter inputFilter = new InputFilter() {
            @Override/*from w w w  .ja  v a 2  s .co  m*/
            public CharSequence filter(CharSequence source, //
                    int start, int end, Spanned dest, int dstart, int dend) {
                if (source.toString().matches("^[0-9]+$")) {
                    return source;
                } else {
                    return "";
                }
            }
        };
        return new InputFilter[] { inputFilter };
    }
}

Related Tutorials