Android setOnPageChangeListener 过时了怎么办?

今天使用ViewPager发现setOnPageChangeListener的方法居然过期了,而且AS编译不通过了,最后查了一下原来把set换成add了,代码如下:

  • setOnPageChangeListener
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {

}

@Override
public void onPageScrollStateChanged(int state) {

}
});
  • addOnPageChangeListener
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
    selectedTab(position);
}

@Override
public void onPageScrollStateChanged(int state) {

}
});

 

posted @ 2018-01-05 16:56  星辰之力  阅读(201)  评论(0编辑  收藏  举报