歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android EditText失去焦點可以干的事情

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

日期:2017/3/1 11:15:16   编辑:Linux編程
EditText失去焦點可一干點事情 代碼:
  1. package com.teego.activity;
  2. import Android.app.Activity;
  3. import android.os.Bundle;
  4. import android.text.InputType;
  5. import android.view.View;
  6. import android.view.View.OnFocusChangeListener;
  7. import android.widget.EditText;
  8. import android.widget.Toast;
  9. public class HelloEditText extends Activity {
  10. private EditText edit1, edit2, edit3;
  11. @Override
  12. public void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.main);
  15. edit1 = (EditText) findViewById(R.id.ed_txt1);
  16. edit2 = (EditText) findViewById(R.id.ed_txt2);
  17. edit3 = (EditText) findViewById(R.id.ed_txt3);
  18. edit1.setInputType(InputType.TYPE_NULL);
  19. edit2.setInputType(InputType.TYPE_NULL);
  20. edit3.setInputType(InputType.TYPE_NULL);
  21. edit1.setOnFocusChangeListener(new OnFocusChangeListener() {
  22. @Override
  23. public void onFocusChange(View v, boolean hasFocus) {
  24. if(edit1.hasFocus()==false){
  25. Toast.makeText(HelloEditText.this, "可以進行驗證1", Toast.LENGTH_SHORT).show();
  26. }
  27. }
  28. });
  29. edit2.setOnFocusChangeListener(new OnFocusChangeListener() {
  30. @Override
  31. public void onFocusChange(View v, boolean hasFocus) {
  32. Toast.makeText(HelloEditText.this, "可以進行驗證2", Toast.LENGTH_SHORT).show();
  33. }
  34. });
  35. edit3.setOnFocusChangeListener((new OnFocusChangeListener() {
  36. @Override
  37. public void onFocusChange(View v, boolean hasFocus) {
  38. // Toast.makeText(HelloEditText.this, "可以進行驗證3", Toast.LENGTH_SHORT).show();
  39. }
  40. }));
  41. }
  42. }
Copyright © Linux教程網 All Rights Reserved