Android EditText失去焦点可以干的事情
EditText失去焦点可一干点事情代码:
[*]package com.teego.activity;
[*]
[*]
[*]import Android.app.Activity;
[*]import android.os.Bundle;
[*]import android.text.InputType;
[*]import android.view.View;
[*]import android.view.View.OnFocusChangeListener;
[*]import android.widget.EditText;
[*]import android.widget.Toast;
[*]
[*]public class HelloEditText extends Activity {
[*] private EditText edit1, edit2, edit3;
[*]
[*] @Override
[*] public void onCreate(Bundle savedInstanceState) {
[*] super.onCreate(savedInstanceState);
[*] setContentView(R.layout.main);
[*] edit1 = (EditText) findViewById(R.id.ed_txt1);
[*] edit2 = (EditText) findViewById(R.id.ed_txt2);
[*] edit3 = (EditText) findViewById(R.id.ed_txt3);
[*]
[*] edit1.setInputType(InputType.TYPE_NULL);
[*] edit2.setInputType(InputType.TYPE_NULL);
[*] edit3.setInputType(InputType.TYPE_NULL);
[*]
[*] edit1.setOnFocusChangeListener(new OnFocusChangeListener() {
[*]
[*] @Override
[*] public void onFocusChange(View v, boolean hasFocus) {
[*] if(edit1.hasFocus()==false){
[*] Toast.makeText(HelloEditText.this, "可以进行验证1", Toast.LENGTH_SHORT).show();
[*] }
[*]
[*] }
[*] });
[*] edit2.setOnFocusChangeListener(new OnFocusChangeListener() {
[*]
[*] @Override
[*] public void onFocusChange(View v, boolean hasFocus) {
[*]
[*] Toast.makeText(HelloEditText.this, "可以进行验证2", Toast.LENGTH_SHORT).show();
[*] }
[*] });
[*] edit3.setOnFocusChangeListener((new OnFocusChangeListener() {
[*]
[*] @Override
[*] public void onFocusChange(View v, boolean hasFocus) {
[*]
[*]// Toast.makeText(HelloEditText.this, "可以进行验证3", Toast.LENGTH_SHORT).show();
[*] }
[*] }));
[*] }
[*]
[*] }
本文摘自:http://www.linuxidc.com/Linux/2011-10/44789.htm
页:
[1]