简体   繁体   English

notifyDataSetChanged()不刷新我的视图

[英]notifyDataSetChanged() doesn't refresh my view

I'm doing this in an AsyncTask, everything working fine but my view is not directly refreshed, 我在AsyncTask中执行此操作,一切正常但我的视图没有直接刷新,

but if i just scroll a bit on my listView the data are refreshed 但如果我只是在我的listView上滚动一点,数据就会被刷新

 ArrayList<Project> listProject =  taskLiteApplication.getListProjectWithStatus(Integer.parseInt(status[0]));


            //set adapter
            projectBaseAdapter.replaceData(listProject);

            //display projects on screen
            projectBaseAdapter.notifyDataSetChanged();

I try to call refreshDrawableState() on my listView and it doesn't work as well and invalidate() too 我尝试在listView上调用refreshDrawableState(),它也不能正常工作并且也无效()

Any UI updates from an AsyncTask should be done in the onPreExecute and the onPostExecute methods of the AsyncTask class. 来自AsyncTask的任何UI更新都应该在onPreExecuteonPostExecute方法中完成。

So in your case, after your AsyncTask is complete, you want to update the UI. 因此,在您的情况下,在AsyncTask完成后,您需要更新UI。 Therefore you should override the onPostExecute method of your AsyncTask , and in that method call projectBaseAdapter.notifyDataSetChanged(); 因此,您应该覆盖AsyncTask的onPostExecute方法,并在该方法中调用projectBaseAdapter.notifyDataSetChanged();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM