0
我有一些問題,當我重裝recyclerView(讀取數據)都與新的數據同步,而不是圖片是內部ViewPagerRecyclerView不同步的新加載的圖像
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它與所有圖像我沒有任何線索發生這是爲什麼如果發生有人知道那麼請你指導我如何解決這一問題
是不是會造成問題?因爲意見不可回收,所以意味着更多的工作效率降低。糾正我,如果我錯了 –
甚至嘗試你的解決方案沒有做任何改變 –
它效率較低,但由於有如果在bindViewHolder(),如果還有其他,我認爲這可能是導致問題。我想這是在你正在更新「信息」類的數據的類中。你怎麼更新數據並調用'notifyDataSetChanged()'? –