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

后端 未结 1 1752
情歌与酒
情歌与酒 2021-01-23 18:16

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 not

1条回答
  •  后悔当初
    2021-01-23 18:30

    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();
           } 
         });
    

    0 讨论(0)
提交回复
热议问题