Android

android EditText InputFilter

Machine_웅 2022. 10. 25. 13:27
728x90
반응형
temp.setFilters(new InputFilter[]{ filter_nonStartZero });

시작값 0 막기 

    // + JJW 시작값 0제한 
    protected InputFilter filter_nonStartZero = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

            String replacement = source.subSequence(start, end).toString();
            String newVal = dest.toString().substring(0, dstart) + replacement +dest.toString().substring(dend, dest.toString().length());

            Pattern ps = Pattern.compile("^[1-9]+$");
            if( newVal.length() == 1 &&!ps.matcher(source).matches()){
                return "";
            }
            return source;
        }
    };
728x90
반응형

'Android' 카테고리의 다른 글

안드로이드 UI 명칭 ( 수집중 )  (0) 2022.12.28
Android _ Pixel GridView ( feat. Canvas )  (0) 2022.12.13
Android wifi state Receiver  (0) 2022.10.25
Android Gradle ?? - Android 빌드시스템  (0) 2022.09.17
Android UI 파편화 관련  (0) 2022.09.01