package com.example.eg16_2;

import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	TextView textview;
	EditText edittext_num;
	EditText edittext_pass; 

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		/**
		* 获得TextView对象
		* 获得两个EditTextView对象
		*/
		textview = (TextView)findViewById(R.id.textView1);
		edittext_num = (EditText)findViewById(R.id.editText1);
		edittext_pass= (EditText)findViewById(R.id.editText2);
		/**
		* 对EditText进行监听
		* 获得编辑框里面的内容并显示
		*/
		edittext_num.addTextChangedListener(new TextWatcher() {
					
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {		
				//if(!(textview.getText().toString()==null))
					textview.setText("edittext_num:"+edittext_num.getText().toString());
			}
					
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
				int after) {
					// TODO Auto-generated method stub	
			}
					
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub	
			}
		});
						
		edittext_pass.addTextChangedListener(new TextWatcher() {
					
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				//if(!(textview.getText().toString()==null))
					textview.setText("你正在编辑edittext_pass");
			}

			public void beforeTextChanged(CharSequence s, int start, int count,int after) {
				// TODO Auto-generated method stub
			}
						
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
