Android EditText失去焦点可以干的事情


EditText失去焦点可一干点事情    代码:
  1. package com.teego.activity;  
  2.   
  3.   
  4. import Android.app.Activity;  
  5. import android.os.Bundle;  
  6. import android.text.InputType;  
  7. import android.view.View;  
  8. import android.view.View.OnFocusChangeListener;  
  9. import android.widget.EditText;  
  10. import android.widget.Toast;  
  11.   
  12. public class HelloEditText extends Activity {  
  13.     private EditText edit1, edit2, edit3;  
  14.   
  15.     @Override  
  16.     public void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.main);  
  19.         edit1 = (EditText) findViewById(R.id.ed_txt1);  
  20.         edit2 = (EditText) findViewById(R.id.ed_txt2);  
  21.         edit3 = (EditText) findViewById(R.id.ed_txt3);  
  22.           
  23.         edit1.setInputType(InputType.TYPE_NULL);  
  24.         edit2.setInputType(InputType.TYPE_NULL);  
  25.         edit3.setInputType(InputType.TYPE_NULL);  
  26.   
  27.         edit1.setOnFocusChangeListener(new OnFocusChangeListener() {  
  28.   
  29.             @Override  
  30.             public void onFocusChange(View v, boolean hasFocus) {  
  31.                 if(edit1.hasFocus()==false){  
  32.                     Toast.makeText(HelloEditText.this, "可以进行验证1", Toast.LENGTH_SHORT).show();     
  33.                 }  
  34.                   
  35.             }  
  36.         });  
  37.         edit2.setOnFocusChangeListener(new OnFocusChangeListener() {  
  38.   
  39.             @Override  
  40.             public void onFocusChange(View v, boolean hasFocus) {  
  41.                   
  42.                 Toast.makeText(HelloEditText.this, "可以进行验证2", Toast.LENGTH_SHORT).show();     
  43.             }  
  44.         });  
  45.         edit3.setOnFocusChangeListener((new OnFocusChangeListener() {  
  46.   
  47.             @Override  
  48.             public void onFocusChange(View v, boolean hasFocus) {  
  49.   
  50. //              Toast.makeText(HelloEditText.this, "可以进行验证3", Toast.LENGTH_SHORT).show();     
  51.             }  
  52.         }));  
  53.     }  
  54.   
  55.     }  
  • 1
  • 2
  • 下一页

相关内容