android EditView自动判断输入长度,并限制字数,然后将光标停在最后




mRemark_Et.addTextChangedListener(new TextWatcher()
        {//EditView自动判断输入长度
            
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count)
            {
                // TODO Auto-generated method stub
                
            }
            
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after)
            {
                // TODO Auto-generated method stub
                
            }
            
            @Override
            public void afterTextChanged(Editable s)
            {
                String content = mRemark_Et.getText().toString();
                int l = content.length();
                mRemarkXianZhi.setText(l + "");//需要将数字转成字符串
                if (l > 30)
                {
                    mRemark_Et.setText(content.substring(0, 30));
                    mRemark_Et.setSelection(30);//EditView设置光标到最后
                }
                
            }
        });


你可能感兴趣的:(android)