android监听edittext输入事件



         
         
         
         
package com.example.frametest;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	public final  static int ANIM_COUNT = 4;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    //    setContentView(new FrameView(this));
       setContentView(R.layout.main1);

//       
       final TextView tv1 = (TextView)findViewById(R.id.monitor_text0);
       final TextView tv2 = (TextView)findViewById(R.id.monitor_text1);
       final TextView tv3 = (TextView)findViewById(R.id.monitor_text2);
       
       EditText et_monitor = (EditText)findViewById(R.id.monitor_edit_text0);
       et_monitor.addTextChangedListener(new TextWatcher() {
		
		@Override
		public void onTextChanged(CharSequence str, int start, int before, int count) {
			// TODO Auto-generated method stub
			//str输入框改变后的字符信息
			//start 输入后字符串其实位置
			// before 输入后起始光标位置
			//一共输入的字符个数
		    tv1.setText("输入字符串"+str.toString()+"起始光标"+start+"一共输入"+count);
		}
		
		@Override
		public void beforeTextChanged(CharSequence str, int start, int count,
				int after) {
			// TODO Auto-generated method stub
			   //text  输入框中改变前的字符串信息
            //start 输入框中改变前的字符串的起始位置
            //count 输入框中改变前后的字符串改变数量一般为0
            //after 输入框中改变后的字符串与起始位置的偏移量
			 tv2.setText("输入前字符串 [ " + str.toString() + " ]起始光标 [ " + start + " ]结束偏移量  [" + after + " ]");
		}
		
		@Override
		public void afterTextChanged(Editable edit) {
			// TODO Auto-generated method stub
			 //edit  输入结束呈现在输入框中的信息
            tv3.setText("输入结束后的内容为 [" + edit.toString()+" ] 即将显示在屏幕上");
		}
	});
    }

   
    
}

上图

android监听edittext输入事件_第1张图片

你可能感兴趣的:(android)