AutoCompleteTextView 检测何时从用户编辑的列表中选择条目 [英] AutoCompleteTextView detect when selected entry from list edited by user
问题描述
我有一个 AutoCompleteTextView
我用来从长列表中选择一个项目.用户应该只能从列表中选择一个预定的项目.他们不应该能够输入自己的项目.
I have an AutoCompleteTextView
I use to select an item from a long list. The user should only be able to select a predetermined item from the list. They should not be able to enter their own item.
我检查以确保他们只提交列表中的一个项目的方法是使用 setOnItemClickListener
来触发布尔标志.问题在于布尔标志设置为true后,他们仍然可以编辑项目的选定文本.我需要检测到这一点并再次将布尔标志设置为 false.我该怎么做呢.我看到了使用 onKeyDown
的建议,但我不确定如何实现.
The way I check to make sure they submit only an item from the list is to use setOnItemClickListener
to trigger a boolean flag. The problem is that after the boolean flag is set to true, they can still edit the selected text of the item. I need to detect this and set the boolean flag to false again. How do I do this. I have seen a suggestion to use onKeyDown
, but I am not sure how to implement this.
推荐答案
您可以添加文本更改的侦听器:
You can add text changed listener:
autoCompleteTextView.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) {
}
});
这篇关于AutoCompleteTextView 检测何时从用户编辑的列表中选择条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!