2014-11-06 39 views
0

我已经将setOnKeyListener添加到AutoCompleteTextView,但是当我按下键时,onKey不会被调用。只有当我按下完成时才会调用... 任何人都可以帮忙吗?onKeyListner没有调用,直到完成按

AutoCompleteTextView userInput = (AutoCompleteTextView) chooseContactView.findViewById(R.id.choose_contact); 
    userInput.setOnKeyListener(new OnKeyListener() { 

     @Override 
     public boolean onKey(View v, int keyCode, KeyEvent event) { 
      // TODO Auto-generated method stub 
      String input = ((AutoCompleteTextView)v).getText().toString(); 

      readContactData(input); 


      return false; 
     } 
    }); 
+1

你确定你不想文本改变听众? http://developer.android.com/reference/android/widget/TextView.html#addTextChangedListener(android.text.TextWatcher) – Blacklight 2014-11-06 09:13:12

回答

0

您应该使用addTextChangedListener至于TextView更改的侦听器。

+0

谢谢!它的工作...我以为我检查了所有的听众:) – user3698465 2014-11-06 09:22:38

0

您还可以使用TextWatcher例如为:

userInput.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
     } 

     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
     } 

     @Override 
     public void afterTextChanged(Editable s) { 
     } 
    }); 
相关问题