Android, ListView IllegalStateException: “The content of the adapter has changed but ListView did not receive a notification”

后端 未结 25 2393
执念已碎
执念已碎 2020-11-22 16:59

What I want to do: run a background thread which calculates ListView contents and update ListView partially, while results are calculated.

W

25条回答
  •  爱一瞬间的悲伤
    2020-11-22 17:41

    i had the same problem. finally i got the solution

    before updating listview, if the soft keypad is present close it first. after that set data source and call notifydatasetchanged().

    while closing keypad internally listview will update its ui. it keep calling till closing keypad. that time if data source change it willl throw this exception. if data is updating in onActivityResult, there is a chance for same error.

     InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    
            view.postDelayed(new Runnable() {
                @Override
                public void run() {
                    refreshList();
                }
            },100L);
    

提交回复
热议问题