EditText输入事件监听

尝试了一下EditText的监听事件,发现:

1. 这样做可以正常监听EditText的输入

EditText et = new EditText();
et.addTextChangedListener(new TextWatcher() {
			@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) {
				// TODO Auto-generated method stub
				Log.i("TAG",et.getText().toString());
			}
		});

 

2.为什么另外一种方法监听不到呢?

EditText et = new EditText();
et.setOnKeyListener(new EditText.OnKeyListener()      
{        
	@Override        
	public boolean onKey(View arg0, int arg1, KeyEvent arg2)        {          
		// TODO Auto-generated method stub        
 		 Log.i("TAG",et.getText().toString());       
 		return false;      
 	 }    
});  

 

3.第一种方法中,为什么afterTextChanged方法中不能改变被监听的EditText的内容呢?

 

 

 

 

你可能感兴趣的:(EditText)