如何避免自动完成下拉列表时,文本编程设置出现? [英] How can I avoid autocomplete dropdown appearing when text is programatically set?

查看:212
本文介绍了如何避免自动完成下拉列表时,文本编程设置出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的布局AutoCompleteTextView。我也有一个替代的方式来选择它们是present在AutoCompleteTextView相同的项目。当选择的替代方式,我填充通过在AutoCompleteTextView值:

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 selected, I populate the value in the AutoCompleteTextView via:

autoCompleteTextView.setText(valueFromAlternativeSource);

其中, valueFromAlternativeSource 是有效自动完成选项之一。这个麻烦的是,当的setText被称为自动完成下拉菜单出现。把下面这行后,上述不工作:

where valueFromAlternativeSource is one of the valid auto complete options. The trouble with this is that the autocomplete dropdown appears when setText is called. Putting the following line after the above doesn't work:

autoCompleteTextView.dismissDropDown();  //Doesn't work.  Why?

为什么解雇下拉任何想法不工作或其他方式,我可以关闭该下拉列表?

Any ideas on why dismiss dropdown isn't working or other ways I could dismiss the dropdown?

推荐答案

这工作正常,我并没有那么复杂:

This works fine for me and is less complex:

ListAdapter adapter = autoCompleteTextView.getAdapter();
autoCompleteTextView.setAdapter(null);
autoCompleteTextView.setText("whatever");
autoCompleteTextView.setAdapter(adapter);

这篇关于如何避免自动完成下拉列表时,文本编程设置出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆