查看没有调用

时间:2016-06-09 13:05:36

标签: android notifications

这是我的适配器:

 public class MediaPreviewAdapter extends PagerAdapter {


    Context mContext;
    LayoutInflater mLayoutInflater;
    List<MediaFiles> media;

    public MediaPreviewAdapter(Context context, List<MediaFiles> mediaList) {
        mContext = context;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        media = mediaList;
    }

    @Override
    public int getCount() {
        return media.size();
    }


    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

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

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        View itemView = mLayoutInflater.inflate(R.layout.media_preview_adapter, container, false);

        ImageView imageView = (ImageView) itemView.findViewById(R.id.image1);
        TextView textView = (TextView) itemView.findViewById(R.id.text1);

        if (!TextUtils.isEmpty(media.get(position).getDescription())) {
            textView.setText(media.get(position).getDescription());
        }

        Bitmap bitmap = Util.returnBitmap(media.get(position).getKey(), mContext);

        if (bitmap != null) {
            imageView.setImageBitmap(bitmap);
        }

        container.addView(itemView);

        return itemView;
    }

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


}

我这样设置:

 vPager = new ViewPager(this);
        vPager.setPageTransformer(true, new ZoomOutPageTransformer());
        MediaPreviewAdapter adapter = new MediaPreviewAdapter(this, *List<etc> example*);
        vPager.setAdapter(adapter);

我的问题是从不调用Adapter类的instantiateItem。我怎么解决呢?我已经读过,对于你拥有的项目和下一个项目,instantiateItem首先被调用两次,但是我的活动从未被调用过。

0 个答案:

没有答案