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();
}
}));
}
}