Android-调用setText后未显示AutoCompleteTextView [英] Android - AutoCompleteTextView not showing after setText is called
问题描述
我在AutoCompleteTextView
上遇到了一个奇怪的问题.
I'm having a weird issue with AutoCompleteTextView
.
我有一个AutoCompleteTextView
,在键入时显示城市的建议.
通过JSON
从远程服务器检索城市列表.当我使用软键盘或软键盘上的Mic
按钮时,建议可以正常工作. AutoCompleteTextView
确实显示了建议的城市.
I have a AutoCompleteTextView
that shows suggestions of cities when typing in it.
The list of cities is retrieved from a remote server via JSON
. When I use the soft keyboard or the Mic
Button on the soft keyboard, the suggestions work fine. AutoCompleteTextView
does show the suggested cities.
但是,当我尝试使用myAutoCompleteTextView.setText("Chi")
设置文本时出现问题,自动完成不显示.
我也尝试过myAutoCompleteTextView.append("Chi")
,但还是没有运气.
But, I have a problem when I try to set the text using myAutoCompleteTextView.setText("Chi")
, the auto complete does not show..
I have also tried myAutoCompleteTextView.append("Chi")
but still no luck..
适配器在那里,只是没有显示建议.
The adapter is there, its just that the suggestions don't show.
有什么提示吗?
谢谢.
推荐答案
是的,在AutocompleteTextview
中存在一个错误,该错误显示使用setText("");
方法的默认建议.
Yes you are right there is a bug in AutocompleteTextview
to show default suggestion using setText("");
method.
但是您可以通过添加一些下面的代码行来实现.
But you can achieve this by adding some more lines of code as below.
autoText.postDelayed(new Runnable() {
@Override
public void run() {
autoText.showDropDown();
}
},500);
autoText.setText("chi");
autoText.setSelection(autoText.getText().length());
这篇关于Android-调用setText后未显示AutoCompleteTextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!