EditText(7)EditText输入事件监听

 

EditText.addTextChangedListener(TextWatcher watcher);

 

 1 void initSearch(){
 2         search = (EditText) findViewById(R.id.search);
 3 
 4         search.setOnEditorActionListener(new EditText.OnEditorActionListener(){
 5 
 6             @Override
 7             public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
 8 
 9                 if (actionId == EditorInfo.IME_ACTION_SEND){
10                     Snackbar snackbar = Snackbar.make(v, "虽然是search,但是是actionSend", Snackbar.LENGTH_SHORT);
11                     snackbar.show();
12                     return true;
13                 }
14                 return false;
15             }
16         });
17 
18         search.addTextChangedListener(new TextWatcher() {
19             @Override
20             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
21                 System.out.println("beforeTextChanged :" + s);
22             }
23 
24             @Override
25             public void onTextChanged(CharSequence s, int start, int before, int count) {
26                 System.out.println("onTextChanged :" + s);
27                 actionBar.setTitle(s);
28 
29             }
30 
31             @Override
32             public void afterTextChanged(Editable s) {
33                 System.out.println("afterTextChanged :" + s);
34             }
35         });
36 
37     }

 

posted @ 2016-06-16 22:42  f9q  阅读(231)  评论(0编辑  收藏  举报