How to use the TextWatcher class in Android?

前端 未结 9 1028
独厮守ぢ
独厮守ぢ 2020-11-22 02:30

Can anyone tell me how to mask the substring in EditText or how to change EditText substring input to password type

9条回答
  •  后悔当初
    2020-11-22 03:12

    if you implement with dialog edittext. use like this:. its same with use to other edittext.

    dialog.getInputEditText().addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int before, int count) {
        }
    
        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            if (start<2){
                    dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
                }else{
                    double size =  Double.parseDouble(charSequence.toString());
                    if (size > 0.000001 && size < 0.999999){
                        dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                    }else{
                        ToastHelper.show(HistoryActivity.this, "Size must between 0.1 - 0.9");
                        dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
                    }
    
                }
        }
    
        @Override
        public void afterTextChanged(Editable editable) {
    
        }
    });
    

提交回复
热议问题