How can I avoid autocomplete dropdown appearing when text is programmatically set?

后端 未结 5 1743
说谎
说谎 2021-02-07 04:16

I have an AutoCompleteTextView in my layout. I also have an alternative way to select the same items which are present in the AutoCompleteTextView. When the alternative way is

5条回答
  •  梦毁少年i
    2021-02-07 04:56

    My solution (but I don't like it, there must be something better):

    autoCompleteTextView.setText(valueFromAlternativeSource);
    autoCompleteTextView.setDropDownHeight(0);
    
    autoCompleteTextView.setOnKeyListener(new OnKeyListener(){
    
       @Override
       public boolean onKey(View v, int keyCode, KeyEvent event) {
           autoCompleteTextView.setDropDownHeight(LayoutParams.WRAP_CONTENT);
       }
    }
    

提交回复
热议问题