现在的位置: 首页 > 综合 > 正文

EditText输入字符变化事件

2018年09月11日 ⁄ 综合 ⁄ 共 729字 ⁄ 字号 评论关闭
editText.addTextChangedListener(new TextWatcher(){
 
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
                //s:变化后的所有字符
                Toast.makeText(getApplicationContext(), "变化:"+s, Toast.LENGTH_SHORT).show();
            }
 
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub
                //s:变化前的所有字符; start:字符开始的位置; count:变化前的总字节数;after:变化后的字节数
                Toast.makeText(getApplicationContext(), "变化前:"+s+";"+start+";"+count+";"+after, Toast.LENGTH_SHORT).show();
            }
 
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub
                //S:变化后的所有字符;start:字符起始的位置;before: 变化之前的总字节数;count:变化后的字节数
                Toast.makeText(getApplicationContext(), "变化后:"+s+";"+start+";"+before+";"+count, Toast.LENGTH_SHORT).show();
            }
             
        });

抱歉!评论已关闭.