【问题标题】:EditText changedListener is not getting calledEditText changedListener 没有被调用
【发布时间】:2016-11-04 09:22:23
【问题描述】:

我使用EditText 过滤ListView 中的一些值。

到目前为止它有效,但我有一个问题。首先是我的代码:

final EditText mEditText = (EditText) this.findViewById(R.id.filterEditText);
mEditText.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { }

    @Override
    public void afterTextChanged(Editable editable) {
        String mFilter = editable.toString();
        mListViewUpdater.setFilter(mFilter);
        Log.d("Editable", editable.toString());
    }
}

afterTextChanged() 方法在我输入内容时被调用,并且过滤器被应用并工作。

但是,如果我删除 EditText 中的所有内容,ListView 将保持上次过滤状态,直到我关闭键盘,然后它再次显示所有值。

如果 EditText 为空但键盘未折叠,是否有办法显示所有值?

最好的问候!

【问题讨论】:

标签: java android user-interface android-edittext


【解决方案1】:

将所有代码放入onTextChanged() 方法而不是afterTextChanged() 方法。

【讨论】:

    猜你喜欢
    • 2017-01-04
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 2019-03-31
    相关资源
    最近更新 更多