我有一个回收站视图,其中包含每次都必须下载图像的项目。这是我的OnBindViewHolder(适配器)的代码:
@Override
public void onBindViewHolder(final BalancesAdapter.MyViewHolder holder, int position) {
Balance balance = balancesList.get(position);
holder.tokenBalance.setText(balance.getBalance() + " " + balance.getTokenSymbol());
if(Utils.loadLogos) {
switch (balance.getTokenSymbol()) {
case "ETH":
holder.tokenLogo.setImageResource(R.drawable.ethereum);
break;
default:
String imageURL = Utils.currentNokuUrl + "/logos/" + balance.getTokenSymbol().toUpperCase() + "-200x200.png";
Glide.with(mContext).load(imageURL).listener(requestListener).error(R.drawable.erc20).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.tokenLogo);
}
}
SharedPreferences sharedPref = mContext.getSharedPreferences("SETTINGS", Context.MODE_PRIVATE);
String settingExchangeRates = sharedPref.getString("EXCHANGE_RATES", null);
if (settingExchangeRates != null && !settingExchangeRates.equals("Disable")) {
String bal = balance.getBalance().replaceAll(",", "");
switch (settingExchangeRates) {
case "ETH":
if (balance.getEthExchangeRate() != null)
holder.exchangeRate.setText(formatterFiat.format(Double.parseDouble(bal) * balance.getEthExchangeRate()) + " Ξ");
break;
case "BTC":
if (balance.getBtcExchangeRate() != null)
holder.exchangeRate.setText(formatterFiat.format(Double.parseDouble(bal) * balance.getBtcExchangeRate()) + " ฿");
break;
case "USD":
if (balance.getUsdExchangeRate() != null)
holder.exchangeRate.setText(formatterFiat.format(Double.parseDouble(bal) * balance.getUsdExchangeRate()) + " $");
break;
case "EUR":
if (balance.getEurExchangeRate() != null)
holder.exchangeRate.setText(formatterFiat.format(Double.parseDouble(bal) * balance.getEurExchangeRate()) + " €");
break;
}
}
}
问题是列表是动态的,当它非常大时,我返回活动按下后续活动的后退按钮,图像被重新加载,产生非常难看的效果。我怎么能让它保留以前的图像?