当选择从列表项由用户编辑的AutoCompleteTextView检测 [英] AutoCompleteTextView detect when selected entry from list edited by user

查看:180
本文介绍了当选择从列表项由用户编辑的AutoCompleteTextView检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 AutoCompleteTextView 我用从一个长长的清单中选择一个项目。用户应该只能够从列表中选择pdetermined项的$ P $。他们应该无法进入自己的项目。

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屋!

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