相关疑难解决方法(0)

在隐藏键盘之前,ListView不会更新

我有一个DialogFragment和它的布局我有一个EditText和一个ListView.Listview基本上显示了联系人列表(最初这个列表有0个项目).当edittext更新的值时,我使用text键入的联系人填充列表EditText.

在用户键入联系人的姓名或电子邮件地址时,EditText我使用了a addTextChangedListener来更新列表和所需的联系人.

我面临的一个奇怪的问题是,只有当我按下后退按钮以在键入后隐藏键盘时,列表(或者可能是布局)才会更新.只要软键盘显示,列表就不会更新(除非是第一次将项目添加到空列表中).

以下是一些更好理解的代码.

CustomDialogFragment.java

(在onCreateView中):

    // Set list adapter for contacts list
    contactsList = (ListView) shareView.findViewById(R.id.contactList);
    emailContactAdapter = new EmailContactAdapter(getActivity(), emailContacts, shareFragment);
    contactsList.setAdapter(emailContactAdapter);

    // Implement Phone-book contact share
    sendToInput = (EditText) shareView.findViewById(R.id.contact_name);
    sendToInput.addTextChangedListener(onContactNameSearch);
Run Code Online (Sandbox Code Playgroud)

在onContactNameSearch(TextWatcher)中:

public TextWatcher onContactNameSearch = new TextWatcher() {

    private generics commonMethods = new generics();

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        emailContacts.clear();
    }

    @Override
    public …
Run Code Online (Sandbox Code Playgroud)

android android-listview android-dialogfragment

9
推荐指数
1
解决办法
1301
查看次数

带有过滤器的Listview将不会刷新,直到键盘被隐藏或按下返回

我有一个列表视图,显示联系人列表.我在listview上方的布局中添加了EditText,因此我可以使用Filter进行搜索.我使用EditText上的onTextChanged Listener实现了这个.我的listview适配器是一个自定义适配器,它扩展了BaseAdapter并实现了Filterable.我的过滤器可以正常工作.问题是,当我输入时,数据集会刷新,但列表视图本身不会刷新,直到我隐藏键盘或按返回键.如果我在EditText中输入一些文本后尝试点击列表视图但在关闭键盘或按回车之前,我收到此错误:

java.lang.IllegalStateException: The content of the adapter has changed 
but ListView did not receive a notification. Make sure the content of 
your adapter is not modified from a background thread, but only from the UI thread.
Run Code Online (Sandbox Code Playgroud)

现在我肯定不会从UI线程以外的线程修改适配器的内容.

谁能解释一下可能导致这个问题的原因?

实际上,我通过调用找到了一种解决方法,Activity.onContentChanged()但我仍然很好奇为什么我实际上需要手动刷新.

android listview filter

4
推荐指数
1
解决办法
1888
查看次数