Recyclerview中

时间:2017-11-01 02:54:01

标签: android android-recyclerview

我在我的Android应用程序中遇到一种情况,用于显示带有图像的用户列表。

场合 加载活动后,我从服务器获取用户列表并在回收站视图中显示它们。对于用户的每个图像,我首先检查图像是否被下载,如果是,则从高速缓存中取出图像,否则从服务器下载。下载后我会显示图像

发生了什么 缓存上可用的图像设置正常,但对于其图像不可用的用户,其他用户的图像设置在那里。向上和向下滚动正确的图像集后。我想这是因为recyclerview的行为,因为它不会创建相同数量的视图持有者实例,因为适配器中存在许多项目。

以下是我在视图库中设置图片的方式

if(ProfileUtility.localProfilePicExists(user.getProfileImageName(), itemView.getContext())) {
            Log.v(Constant.TAG, "Showing Profile image in small user card");
            Picasso.with(itemView.getContext()).load(ImageUtil.getLocalImageUri(itemView.getContext(),"circle_"+user.getProfileImageName()+".png")).fit().centerCrop().into(this.imgProfile);
        }
        else {
            ProfileUtility.loadProfilePicture(user.getProfileImageName(),this,itemView.getContext()); // this requests download the image and "this" is used to call "complete" method of this view holder where i load image
            PixyfiSession.save(user.getProfileImageName(),imgProfile); //here i save the image view in which i have to show the image
        }

“完整”方法

public void complete(Object o) {
        if (this.progressDialog != null && this.progressDialog.isShowing())
            this.progressDialog.dismiss();
        if(o instanceof ImageDetails) {
            ImageDetails id =(ImageDetails) o;
            if(id.getLocalName() != null && id.getId().equals(user.getProfileImageName()) ) {
                String key = id.getId();
                ImageView imgView = (ImageView) PixyfiSession.get(key);
                Log.v(Constant.TAG, "Showing Profile image in small user card from complete with name:"+"circle_"+id.getLocalName());
                Picasso.with(itemView.getContext()).load(ImageUtil.getLocalImageUri(itemView.getContext(), "circle_"+id.getLocalName())).into(imgView);
            }
        }
}

我有什么遗失的吗?

0 个答案:

没有答案