onPageSelected doesn't work for first page

前端 未结 10 1986
[愿得一人]
[愿得一人] 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:15

    Because I did what was suggested here and it did not work I will post what did work for me was adding the instantiating function to onPageScrolled, like so:

       @Override
       public void onPageScrolled(int arg0, float arg1, int arg2) {
    
               adapter.closeText(arg0, viewPager);
    
        }
    

    Probably the reason it worked is that onPagesScrolled is activated farther down the line of the android task manager, so we prevent the unwanted situation where the page is inflated with skipping the listeners attachment to the view.

提交回复
热议问题