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); } }