学习记录---- viewpager里嵌套listview中adapter的写法

/**

	 * viewpager设配器

	 * @author Administrator

	 *

	 */

	class InvestManageViewPagerAdapter extends PagerAdapter{

		

		private List<View> listViews = new ArrayList<View>();

		

		public  InvestManageViewPagerAdapter( List<View> listViews){

			this.listViews = listViews;

		}



		@Override

		public int getCount() {

			return listViews.size();

		}



		@Override

		public Object instantiateItem(View container, int position) {

			System.out.println("第几个pager=="+position);

			try { 

                if(listViews.get(position).getParent()==null)

                    ((ViewPager) container).addView(listViews.get(position), 0);  

                else{

                    ((ViewGroup)listViews.get(position).getParent()).removeView(listViews.get(position));

                    ((ViewPager) container).addView(listViews.get(position), 0); 

                }

            } catch (Exception e) {  

                e.printStackTrace();  

            }  

			return listViews.get(position);

		}

		

		@Override

		public void destroyItem(View container, int position, Object object) {

			((ViewPager)container).removeView((View)object);

		}



		@Override

		public boolean isViewFromObject(View view, Object object) {

			return view == ((View)object);

		}





	}

 

你可能感兴趣的:(viewpager)