我的recyclerView在重新加载(获取数据)时遇到一些问题,所有内容都与新数据同步,但与ViewPager内部的图像不同
onBindViewHolder :
@Override
public void onBindViewHolderImpl(final RecyclerView.ViewHolder viewHolder, ParallaxRecyclerAdapter<Information> adapter, final int i) {
final Information current = finalContent.get(i);
((ViewHolder) viewHolder).DESCRIPTION.setText(current.description);
((ViewHolder) viewHolder).IMAGEEXISTENCE.setText(current.imageExistence.toString());
Log.d("TAG1","IMAGEEXISTENCE : "+((ViewHolder) viewHolder).IMAGEEXISTENCE.getText() +" position : "+i+" link : "+current.FileUrl);
//checking if image exists if yes then set the pager size else set it to 0
if (((ViewHolder) viewHolder).IMAGEEXISTENCE.getText().toString().matches("true")) {
//its a string of url's combined with "|"
String[] imgUrlArray = ((current.FileUrl.split("\\| ")));
arrayLists.add(imgUrlArray);
ViewPager mViewPager = ((ViewHolder) viewHolder).viewPager;
mViewPager.getLayoutParams().height = 550;
mViewPager.requestLayout();
String[] mResources = {};
// here am passing the image url to AdapterClass
mResources = arrayLists.get(i);
CarouselAdapter mCustomPagerAdapter = new CarouselAdapter(getContext(), mResources , i);
// here am setting the pagerAdapter for my Pager
mViewPager.setAdapter(mCustomPagerAdapter);
} else {
if image is not exist then am passing a blank url
String[] imgUrlArray = new String[0];
arrayLists.add(imgUrlArray);
}
}
适配器类
public class CarouselAdapter extends PagerAdapter {
private Context mContext;
private LayoutInflater mLayoutInflater;
private String[] mResources;
private int mindex;
public CarouselAdapter(Context context, String[] resources, int index) {
mContext = context;
mResources = resources;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mindex = index;
}
@Override
public int getCount() {
return mResources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View itemView = mLayoutInflater.inflate(R.layout.carousel_imgview, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
// imageView.setImageResource(mResources[position]
// );
if (mResources[position] == null ){
imageView.setImageDrawable(null);
// imageView.getLayoutParams().height = 0;
// imageView.requestLayout();
}else {
final DonutProgress donutProgress = (DonutProgress) itemView.findViewById(R.id.donut_progress);
donutProgress.setTextColor(Color.argb(0,0,0,0));
donutProgress.setUnfinishedStrokeColor(Color.LTGRAY);
donutProgress.setFinishedStrokeColor(Color.GRAY);
donutProgress.setVisibility(View.VISIBLE);
ImageLoader imageLoader = ImageLoader.getInstance();
String newUrl = mResources[position].replaceAll(" ", "");
// for clearing cache
DiskCacheUtils.removeFromCache(newUrl, ImageLoader.getInstance().getDiskCache());
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(true).build();
imageLoader.displayImage(newUrl, imageView , options , new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
donutProgress.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
donutProgress.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
donutProgress.setVisibility(View.GONE);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
Log.d("TAG","onLoadingCancelled");
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
donutProgress.setMax(total);
donutProgress.setProgress(current);
}
});
}
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((RelativeLayout) object);
}
}
我通过打印网址来检查网址和图片存在(布尔)这是完全正确的,只是不知道为什么我的recyclerView没有同步新图像
而是在重新加载数据之后(在数据是新的之后重新加载数据image2在索引2之前)图像的索引被改变了,如果在重新加载image2之前,我的所有图像的索引都被改变了2重新加载后,image2移动到索引1它发生了所有图像我没有任何线索为什么这发生如果有人知道然后请指导我如何解决这个
答案 0 :(得分:0)
尝试
viewHolder.setIsRecyclable(false);
在
onBindViewHolderImpl();