如何在CustomPageAdapter上携带id?

时间:2017-02-20 09:06:03

标签: android android-viewpager android-pageradapter

我有List<Item> mItems

在Gridview活动中提供{id},

i.putExtra("id", item.getDrawableId());

在全屏活动中,我将viewpagerCustomPageAdapter extends PagerAdapter一起使用。像这样;

int id = getIntent().getExtras().getInt("id");
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
CustomPageAdapter mCustomPagerAdapter = new CustomPageAdapter(Fullscreen.this, id);
viewPager.setAdapter(mCustomPagerAdapter);

在CustomPageAdapter中,

public class CustomPageAdapter extends PagerAdapter {

    Context context;
    LayoutInflater layoutInflater;
    int id;

    public CustomPageAdapter(Context context, int id) {
        this.context = context;
        this.layoutInflater = (LayoutInflater) this.context.getSystemService(this.context.LAYOUT_INFLATER_SERVICE);
        this.id = id; // id ?
    }

    @Override
    public int getCount() {
        return id; // ?
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = this.layoutInflater.inflate(R.layout.pager_list_items, container, false);
     //   SubsamplingScaleImageView imageView = (SubsamplingScaleImageView) view.findViewById(R.id.imageView);
     //   imageView.setImage(ImageSource.resource( // here is id));
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}

0 个答案:

没有答案