问题描述
即使我在AutoCompleteTextView上设置了setOnItemClickListener并在其中执行了一些自定义操作,但一旦完成该方法,该列表就会消失并在editbox中打印出object.toString.
Even though I'm setting the setOnItemClickListener on the AutoCompleteTextView and performing some custom operations in it, once that method is done, the list dismisses and prints out the object.toString in the editbox.
我想防止取消选择项目的下拉菜单,并且也希望它不替换编辑框.我怎样才能做到这一点?
I want to prevent dismissal of the dropdown on item select and would also like it to not replace the edit box. How can I achieve this ?
推荐答案
我也想实现与下面的代码相同的实现.
I also want to implement the same i used below code to implement it.
创建一个自定义类并扩展AutoCompleteTextView.
Create a custom class and extend AutoCompleteTextView.
重写dismissDropDown()方法并从其中删除超级调用.将为您工作.
Override dismissDropDown() method and remove the super call from it.Will work for you.
public class CustomAutoComplete extends AutoCompleteTextView {
public NoSelectionAutoComplete(Context context) {
super(context);
}
public NoSelectionAutoComplete(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NoSelectionAutoComplete(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void replaceText(CharSequence text) {
}
@Override
public void dismissDropDown() {
}
}
这篇关于选择项目后,Android阻止了AutoCompleteTextView中的下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!