android EditText 设置密码锁源码


http://blog.csdn.net/jdsjlzx/article/details/25062971

http://blog.csdn.net/jdsjlzx/article/details/25062971

http://blog.csdn.net/jdsjlzx/article/details/25062971

http://blog.csdn.net/jdsjlzx/article/details/25062971

http://blog.csdn.net/jdsjlzx/article/details/25062971

android EditText 设置密码锁源码

分类: Android UI Android开发   165人阅读  评论(0)  收藏  举报
[java]  view plain copy
  1. 先设置监听事件  
  2. private void edit_pass() {  
  3.         tw = new TextWatcher() {  
  4.             // @Override  
  5.             public void beforeTextChanged(CharSequence s, int start, int count,  
  6.                     int after) {  
  7.   
  8.             }  
  9.   
  10.             // @Override  
  11.             public void onTextChanged(CharSequence s, int start, int before,  
  12.                     int count) {  
  13.                 Log.w("Log""----" + s);  
  14.   
  15.             }  
  16.   
  17.             // @Override  
  18.             public void afterTextChanged(Editable s) {  
  19.                 if (s.toString().length() == 1) {  
  20.                     if (pass1.isFocused()) {  
  21.                         pass1.clearFocus();  
  22.                         pass2.requestFocus();  
  23.                     } else if (pass2.isFocused()) {  
  24.                         pass2.clearFocus();  
  25.                         pass3.requestFocus();  
  26.                     } else if (pass3.isFocused()) {  
  27.                         pass3.clearFocus();  
  28.                         pass4.requestFocus();  
  29.                     } else if (pass4.isFocused()) {  
  30.                         pass4.clearFocus();  
  31.                         InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
  32.                         imm.hideSoftInputFromWindow(pass4.getWindowToken(), 0);  
  33.                     }  
  34.                 }  
  35.             }  
  36.   
  37.         };  
  38.     }  
  39. 2.监听edittext  
  40. pass1 = (EditText) findViewById(R.id.edit_pass1);  
  41.  pass2 = (EditText) findViewById(R.id.edit_pass2);  
  42.  pass3 = (EditText) findViewById(R.id.edit_pass3);  
  43.  pass4 = (EditText) findViewById(R.id.edit_pass4);  
  44.  pass1.addTextChangedListener(tw);  
  45.  pass2.addTextChangedListener(tw);  
  46.  pass3.addTextChangedListener(tw);  
  47.  pass4.addTextChangedListener(tw);  
  48. 这就可以,每当你输完一个输入框的时候,焦点自动切到第二个输入框,看效果图  
android EditText 设置密码锁源码_第1张图片

你可能感兴趣的:(android,UI,Android开发)