如何知道EditText何时失去焦点?
当EditText失去焦点时,我需要捕捉其他问题,但是我没有find答案。 
 我用这个OnFocusChangeListener 
 OnFocusChangeListener foco = new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { // TODO Auto-generated method stub } }; 
但是,这对我不起作用。
 实现onFocusChange的setOnFocusChangeListener和hasFocus的布尔参数。 当这是错误的,你已经失去了焦点到另一个控制。 
  EditText txtEdit = (EditText) findViewById(R.id.edittxt); txtEdit.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { // code to execute when EditText loses focus } } }); 
 如果你想分解使用这个接口,让你的Activity实现OnFocusChangeListener() ,例如: 
 public class Shops extends AppCompatActivity implements View.OnFocusChangeListener{ 
 在您的OnCreate您可以添加一个侦听器,例如: 
 editTextReaserch.setOnFocusChangeListener(this); editTextMyWords.setOnFocusChangeListener(this); editTextPhone.setOnFocusChangeListener(this); 
那么android studio会提示你从界面添加方法,接受它…它会像:
 @Override public void onFocusChange(View v, boolean hasFocus) { // todo your code here... } 
因为你有一个分解代码,你只需要这样做:
 @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { editTextReaserch.setText(""); editTextMyWords.setText(""); editTextPhone.setText(""); } if (!hasFocus){ editTextReaserch.setText("BlaBlaBla"); editTextMyWords.setText(" One Two Tree!"); editTextPhone.setText("\"your phone here:\""); } } 
  !hasFocus中的任何代码都是针对失去焦点的项目的行为,应该这样做! 但是要注意,在这种状态下,重点的改变可能会覆盖用户的input! 
它的工作正常
 EditText et_mobile= (EditText) findViewById(R.id.edittxt); et_mobile.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // code to execute when EditText loses focus if (et_mobile.getText().toString().trim().length() == 0) { CommonMethod.showAlert("Please enter name", FeedbackSubmtActivity.this); } } } }); public static void showAlert(String message, Activity context) { final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(message).setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); try { builder.show(); } catch (Exception e) { e.printStackTrace(); } }