onPageSelected doesn't work for first page

前端 未结 10 2073
[愿得一人]
[愿得一人] 2021-01-30 12:30

My pager adapter ( extends PagerAdepter ) has a textview in it. And I update this textview with MainActivity\'s onPageSelected . Its update textview for position > 0 , but start

10条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 13:30

    You probably use some AsyncTasks to load the dataset and it is hard to determine which task will be the last to finish. And only after that last task, when the whole dataset is complete you could call OnPageSelected, because it is doing a flush on the UI over the whole dataset.

    Instead of calling the OnPageSelected-function manually when the page is loaded the first time, rather build up the UI step by step the "normal"-way. Later on, when the user changes the page, the dataset should be complete and it is save to let the update been made in the OnPageSelected-function.

提交回复
热议问题