0

Seriesのオブジェクトのコレクションを保持するのに、RealmRecyclerViewAdapterを使用しています。 APIを使用してSeriesデータを更新すると、アダプタは自動的に更新されますが、表示されるイメージは変更され、正しくありません。私のテストでは、RealmRecyclerViewAdapterコンストラクタを介してfalseに自動更新を設定するとこの動作が停止することに気づいたので、リスト項目を更新するとこれが発生します。また、私がauto-updatetrueに残して、onBindViewHolderの呼び出し中にブレークポイントを設定しても、画像は正しいです。ブレークポイントなしで(フルスピードで)コードを実行すると、間違った画像が表示されます。奇妙なのは、更新後に画像が正しく表示されないことだけです。テキストはまだ正確です。自動更新RealmRecyclerViewAdapterは、更新時に間違ったデータを表示します

これは、この動作を表示するGIFです。ご覧のとおり、データを更新すると、行が更新され、間違ったイメージが表示されます。それはSeries用アニメが含まれている場合

public void onBindViewHolder(ViewHolder holder, int position) { 
    final int adapterPosition = holder.getAdapterPosition(); 
    holder.series = getItem(adapterPosition); 

    final String MALID = holder.series.getMALID(); 

    ... 

    int imageId = App.getInstance().getResources().getIdentifier("malid_" + holder.series.getMALID(), "drawable", "<app-package>"); 
    if (imageId != 0) { 
     Picasso.with(App.getInstance()).load(imageId).fit().centerCrop().into(holder.mPoster); 
    } else { 
     File cacheDirectory = App.getInstance().getCacheDir(); 
     File bitmapFile = new File(cacheDirectory, holder.series.getMALID() + ".jpg"); 

     Picasso.with(App.getInstance()).load(bitmapFile).placeholder(R.drawable.placeholder).fit().centerCrop().into(holder.mPoster); 
    } 

    holder.mAddButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      addSeriesHelper(MALID); 
     } 
    }); 
    holder.mMinusButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      RemoveSeriesDialogFragment dialogFragment = RemoveSeriesDialogFragment.newInstance(self, MALID, adapterPosition); 
      dialogFragment.show(seriesFragment.getMainActivity().getFragmentManager(), TAG); 
     } 
    }); 
} 

私は最初のアプリのリソースを確認してください。ここで

https://gyazo.com/88d5735796770b1573bdd518ce53ed44

行の画像が設定されている onBindViewHolderの抜粋です。そうでない場合は、キャッシュされたバージョンが使用可能かどうかをチェックします。

答えて

2
if (!(photoPath.isEmpty())) { 

      int defaultImagePath = R.drawable.default_thumb; 
      int errorImagePath = R.drawable.damaged_image; 
      holder.mImageView.setImageResource(defaultImagePath); 

      String uri = photoPath; 
      loadImageWithGlide(mContext, holder.mImageView, uri, defaultImagePath, 
        errorImagePath); 
     } 


     public static void loadImageWithGlide(final Context context, ImageView theImageViewToLoadImage, 
              String theLoadImagePath, int theDefaultImagePath, int tehErrorImagePath) { 
     if (context == null) return; 

     //placeHolderUrl=R.drawable.ic_user; 
     //errorImageUrl=R.drawable.ic_error; 
     Glide.with(context) //passing context 
       .load(theLoadImagePath) //passing your url to load image. 
       .placeholder(theDefaultImagePath) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url. 
       .error(tehErrorImagePath)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is. 
       .diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast. 
       //.animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image. 
       .fitCenter()//this method help to fit image into center of your ImageView 
       .into(theImageViewToLoadImage); //pass imageView reference to appear the image. 

    } 

    add dependencies inside app build.gralde. 
    // glide 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
関連する問題