Android-ViewPager-Adapter

ViewPager:可用于左右滑动、显示不同的画面,使用adapter来实现,也可以左右滑动。

mViewPager.setAdapter(new MenuDetailAdapter ());

 

MenuDetailAdapter具体实现如下:

 1 class MenuDetailAdapter extends PagerAdapter {
 2 
 3     @Override
 4     public int getCount() {
 5         return mPagerList.size();
 6     }
 7 
 8     @Override
 9     public boolean isViewFromObject(View arg0, Object arg1) {
10         return arg0 == arg1;
11     }
12 
13     @Override
14     public Object instantiateItem(ViewGroup container, int position) {
15         TabDetailPager pager = mPagerList.get(position);
16         container.addView(pager.mRootView);
17         pager.initData();
18         return pager.mRootView;
19     }
20 
21     @Override
22     public void destroyItem(ViewGroup container, int positon, Object object) {
23         container.removeView((View)object);
24     }
25 }

 

posted @ 2015-10-08 22:39  lude313  阅读(204)  评论(0编辑  收藏  举报