Android PagerAdapter :: Get Current Item into bitmap

北城余情 提交于 2019-12-07 12:34:24
nostra13

How to get current view - https://stackoverflow.com/a/8638772/913762

and then:

View currentView = ...
ImageView currentImageView = (ImageView) currentView.findViewById(...);
BitmapDrawable bd = (BitmapDrawable) currentImageView.getDrawable();
Bitmap bmp = bd.getBitmap();

The problem comes when you inflate view: it's the same single instance that is used throughout the list, so when your asynchronous loading is complete, the image is changed when the viewpager is trying to paint a different item using the same imageView. Here is how I fix mine.

1)Create a class named ViewHolder

class ViewHolder {
    public ImageView image;
}

2) As soon as you finish inflating, create new ViewHolder object and bind it.

ViewHolder holder = new ViewHolder();
holder.image = (ImageView) imageLayout.findViewById(R.id.image_item_pager);

After that, you can use holder.image as normal ImageView.

Hope this help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!