EditText添加输入变化事件

来源:互联网 发布:淮左名猪网络作品 编辑:程序博客网 时间:2024/06/05 15:12

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

转载自:http://blog.sina.com.cn/s/blog_89429f6d0101alcp.html

原创粉丝点击