后台只返回一个list集合让我去分页,好蛋疼,后来发现也很简单,使用list的一个方法subList搞定!
关键代码:
//展示具体描述 private void initViewPager(List list) { int count = 4; int sp = list.size() / 4; for (int i = 0; i < sp; i++) { List subList = list.subList(i * count, count * (i + 1)); sublists.add(subList); } int s = list.size() % 4; if (s != 0) { List subList = list.subList(list.size() - s, list.size()); sublists.add(subList); } pagerList.clear(); for (int i = 0; i < sublists.size(); i++) { pagerList.add(new SpecificdescriPager(SpecificdescriptionActivity.this, sublists.get(i))); } initDot(); vpViewPager.setAdapter(new MyPagerAdapter()); vpViewPager.setCurrentItem(0);//默认给Viewpager设置选中的页数 updateDesAndDot();//初始化第0页的描述和点 vpViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { updateDesAndDot(); } @Override public void onPageScrollStateChanged(int state) { } }); }代码地址:http://pan.baidu.com/s/1i3X7rLz