I have around 12 CardViews. Each one set the visibility of ImageView at GONE depending about if the "high" variable is true or false but when I scroll down and then scroll up some ImageView widgets disappear and I have to mention that the last one ImageView isn't shown either.
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
Currency currency = currencies.get(i);
Double valor_actual = currencies.get(i).getValores().get(0);
Double valor_anterior = currencies.get(i).getValores().get(1);
viewHolder.textValue.setText(valor_actual.toString());
BigDecimal bigDecimal = null;
if (currency.getHigh()) {
bigDecimal = new BigDecimal(valor_actual).subtract(new BigDecimal(valor_anterior));
viewHolder.textInfo.setTextColor(Color.parseColor("#ff669900"));
// doesn't work properly
viewHolder.imageDown.setVisibility(View.GONE);
}
if (!currency.getHigh()){
bigDecimal = new BigDecimal(valor_anterior).subtract(new BigDecimal(valor_actual));
viewHolder.textInfo.setTextColor(Color.parseColor("#ffcc0000"));
// doesn't work properly
viewHolder.imageUp.setVisibility(View.GONE);
}
String unidad_medida = currency.getUnidad_medida();
if (bigDecimal != null) {
try {
StringBuilder sb = new StringBuilder(currencyFormat(bigDecimal));
if (unidad_medida.equalsIgnoreCase("porcentaje")) {
sb.deleteCharAt(0);
sb.insert(0, "%");
}
viewHolder.textInfo.setText(sb.toString());
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
}
viewHolder.textName.setText(currency.getNombre());
}
here works great
but when I scroll down and back to scroll up the third CardView doesn't show the ImageView :

you need to put Visible in else condition also. Do this for each of the items you've got there as the list item in case of you're setting their visibilities at runtime.
if (currency.getHigh()) {
bigDecimal = new BigDecimal(valor_actual).subtract(new BigDecimal(valor_anterior));
viewHolder.textInfo.setTextColor(Color.parseColor("#ff669900"));
// doesn't work properly
viewHolder.imageDown.setVisibility(View.GONE);
viewHolder.imageUp.setVisibility(View.VISIBLE);
}
else {
bigDecimal = new BigDecimal(valor_anterior).subtract(new BigDecimal(valor_actual));
viewHolder.textInfo.setTextColor(Color.parseColor("#ffcc0000"));
// doesn't work properly
viewHolder.imageDown.setVisibility(View.VISIBLE);
viewHolder.imageUp.setVisibility(View.GONE);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With