Search in sources :

Example 1 with CommonTabPagerAdapter

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

the class WanFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    showLoading();
    /**
     * 注意使用的是:getChildFragmentManager,
     * 这样setOffscreenPageLimit()就可以添加上,保留相邻2个实例,切换时不会卡
     */
    CommonTabPagerAdapter myAdapter = new CommonTabPagerAdapter(getChildFragmentManager(), Arrays.asList("玩安卓", "广场", "问答"));
    myAdapter.setListener(this);
    bindingView.vpGank.setAdapter(myAdapter);
    // 左右预加载页面的个数
    bindingView.vpGank.setOffscreenPageLimit(2);
    myAdapter.notifyDataSetChanged();
    bindingView.tabGank.setupWithViewPager(bindingView.vpGank);
    showContentView();
}
Also used : CommonTabPagerAdapter(com.example.jingbin.cloudreader.view.CommonTabPagerAdapter)

Example 2 with CommonTabPagerAdapter

use of com.example.jingbin.cloudreader.view.CommonTabPagerAdapter 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)

Example 3 with CommonTabPagerAdapter

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

the class CategoryDetailActivity method initData.

private void initData() {
    int cid = getIntent().getIntExtra("cid", 0);
    TreeItemBean mTreeBean = (TreeItemBean) getIntent().getSerializableExtra("CategoryBean");
    bindingView.setTreeItemBean(mTreeBean);
    List<String> mTitleList = new ArrayList<>();
    int initIndex = 0;
    for (int i = 0, len = mTreeBean.getChildren().size(); i < len; i++) {
        WxarticleItemBean childrenBean = mTreeBean.getChildren().get(i);
        mTitleList.add(childrenBean.getName());
        if (childrenBean.getId() == cid) {
            initIndex = i;
        }
    }
    CommonTabPagerAdapter myAdapter = new CommonTabPagerAdapter(getSupportFragmentManager(), mTitleList);
    myAdapter.setListener(position -> CategoryArticleFragment.newInstance(mTreeBean.getChildren().get(position).getId(), mTreeBean.getChildren().get(position).getName(), false));
    bindingView.viewPager.setAdapter(myAdapter);
    myAdapter.notifyDataSetChanged();
    bindingView.tabLayout.setupWithViewPager(bindingView.viewPager);
    // 设置初始位置
    bindingView.viewPager.setCurrentItem(initIndex);
}
Also used : WxarticleItemBean(com.example.jingbin.cloudreader.bean.wanandroid.WxarticleItemBean) CommonTabPagerAdapter(com.example.jingbin.cloudreader.view.CommonTabPagerAdapter) ArrayList(java.util.ArrayList) TreeItemBean(com.example.jingbin.cloudreader.bean.wanandroid.TreeItemBean)

Aggregations

CommonTabPagerAdapter (com.example.jingbin.cloudreader.view.CommonTabPagerAdapter)3 TreeItemBean (com.example.jingbin.cloudreader.bean.wanandroid.TreeItemBean)1 WxarticleItemBean (com.example.jingbin.cloudreader.bean.wanandroid.WxarticleItemBean)1 OnMyPageChangeListener (com.example.jingbin.cloudreader.view.OnMyPageChangeListener)1 ArrayList (java.util.ArrayList)1