ViewPager中,如何知道某个页面从后台到了前台

可以覆写ViewPager的setPrimaryItem方法:

new FragmentStatePagerAdapter(getSupportFragmentManager()) {

...
@Override
            public void setPrimaryItem(ViewGroup container, int position, Object object) {
                super.setPrimaryItem(container, position, object);
                if(object instanceof XXXFragment) {
                    ......
                }
            }
...

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *