zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

android EditText输入变化事件详解

Android事件输入 详解 变化 EditText
2023-09-11 14:18:00 时间

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