Android: using notifyDataSetChanged and getLastVisiblePosition - when the listView is actually updated?

百般思念 提交于 2019-12-02 11:25:24

问题


I want to use getLastVisiblePosition() and apparently it is not giving me the right number after this method (notifyDataSetChanged) has been called. I think this method only notifies the view that there is a change, but the change is triggered later.

When the view is updated, is there an event that I can use and trigger my method, using getLastVisiblePosition?

Please help or tell me what I am doing wrong ;)

Thanks Danail


回答1:


Yes, if you run notifyDatasetChanged(), you need to queue the operation in the post because the view is rendered asynchronously:

     listView.post(new Runnable() { 
       public void run(){ 
         lastPos = listView.getLastVisiblePosition();
       } 
     });


来源:https://stackoverflow.com/questions/6044796/android-using-notifydatasetchanged-and-getlastvisibleposition-when-the-listvi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!