EditTxt设置文本栈溢出

Android在EditTxt的TxtWatch监听器中中直接使用EditTxt的setText()方法后直接报错,栈溢出。使用append()方法后正常,不知道为什么。

 @Override
    public void afterTextChanged(Editable s) {
        if(s!=null)
        Log.d(TAG, "afterTextChanged: s="+s);
        String editText =new String(String.valueOf(s));
        Log.d(TAG, "afterTextChanged: editText=" +editText);
        m = p.matcher(editText.toString());

        if(!m.find()){
            s = s.delete(0,s.length());
            user_custom.append("");
            Toast.makeText(this,"只能输入数字",Toast.LENGTH_SHORT).show();
        }
        if(editText.contains("\n")){
            //收起键盘
            InputMethodManager imm = (InputMethodManager)
                    getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(user_custom.getWindowToken(), 0);
            Log.d(TAG, "afterTextChanged: s.contains=" + editText + "");
            user_custom.setText(editText.replace("\n",""));
//            user_custom.setClickable(false);
            Log.d(TAG, "afterTextChanged: s.delete=" + s.toString());
//            user_custom.setFocusable(false);
            user_custom.setCursorVisible(false);
//            customRadio.setEnabled(false);

        }else{
            user_custom.setCursorVisible(true);
            customRadio.setEnabled(true);
        }

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值