我有滑动条的这个活动
public class EventiPromozioniActivity extends FragmentActivity{
List<Fragment> fragments = new Vector<Fragment>();
List<String> fragmentTitles = new Vector<String>();
// page adapter between fragment list and view pager
private SlidePagerAdapter mSlidePagerAdapter;
// view pager
private ViewPager mViewPager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slide_bar_ricerche);
Bundle extras = getIntent().getExtras();
if (extras != null) {
//
}
// creating fragments and adding to list
fragments.add(Fragment.instantiate(this, First.class.getName()));
fragmentTitles.add("FIRST");
fragments.add(Fragment.instantiate(this, Second.class.getName()));
fragmentTitles.add("SECOND");
mViewPager = (ViewPager) findViewById(R.id.pager);
View pagerStrip = findViewById(R.id.pagerTabStrip);
if (pagerStrip instanceof PagerTabStrip) {
PagerTabStrip pagerTabStrip = (PagerTabStrip) pagerStrip;
pagerTabStrip.setDrawFullUnderline(true);
pagerTabStrip.setTabIndicatorColorResource(android.R.color.black);
// pagerTabStrip.setTextColor(color.white);
} else if (pagerStrip instanceof PagerTitleStrip) {
PagerTitleStrip pagerTitleStrip = (PagerTitleStrip) pagerStrip;
pagerTitleStrip.setTextColor(getResources().getColor(android.R.color.white));//TODO: deprecato
}
this.mSlidePagerAdapter = new SlidePagerAdapter(super.getSupportFragmentManager(), fragments, fragmentTitles);
mViewPager.setAdapter(this.mSlidePagerAdapter);
mViewPager.setCurrentItem(0);
}
}
如何在页面幻灯片时识别?我希望在页面滑动时调用片段内的方法。
我非常感谢您能提供给我的任何帮助
答案 0 :(得分:0)
试试这个,
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrolled(int position, float arg1, int arg2) {
// Check the page is slide And do your stufff
}
@Override
public void onPageScrollStateChanged(int position) {
}
});