Search in sources :

Example 1 with OnMyPageChangeListener

use of com.example.jingbin.cloudreader.view.OnMyPageChangeListener in project CloudReader by youlookwhat.

the class MainActivity method initContentFragment.

private void initContentFragment() {
    // 注意使用的是:getSupportFragmentManager
    CommonTabPagerAdapter adapter = new CommonTabPagerAdapter(getSupportFragmentManager(), Arrays.asList("", "", ""));
    adapter.setListener(this);
    vpContent.setAdapter(adapter);
    // 设置ViewPager最大缓存的页面个数(cpu消耗少)
    vpContent.setOffscreenPageLimit(2);
    vpContent.addOnPageChangeListener(new OnMyPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            switch(position) {
                case 0:
                    setCurrentItem(0);
                    break;
                case 1:
                    setCurrentItem(1);
                    break;
                case 2:
                    setCurrentItem(2);
                    break;
                default:
                    break;
            }
        }
    });
    setCurrentItem(0);
}
Also used : CommonTabPagerAdapter(com.example.jingbin.cloudreader.view.CommonTabPagerAdapter) OnMyPageChangeListener(com.example.jingbin.cloudreader.view.OnMyPageChangeListener)

Aggregations

CommonTabPagerAdapter (com.example.jingbin.cloudreader.view.CommonTabPagerAdapter)1 OnMyPageChangeListener (com.example.jingbin.cloudreader.view.OnMyPageChangeListener)1