Intento animar nuevos elementos en mi ListView. Tengo id-s estable, así que sé exactamente qué elemento animar. El problema proviene del mecanismo de reciclaje de ListView. Llamo a startAnimation en la vista cuando sé que tengo un elemento insertado recientemente. Pero luego, la vista se recicló y se llenó de datos diferentes. Resulta en la interfaz de usuario que anima la fila incorrecta. En algún momento, la vista contenía los datos correctos, pero luego se recicló. Confirmé esto a través de Logcat. ¿Hay alguna manera de resolver esto?Animar elementos de la lista en ListView
EDIT:
public ExpensCursorAdapter(Context context, Cursor c, boolean autoRequery,
CopyOnWriteArraySet<String> fadeAnimateTags) {
super(context, c, autoRequery);
this.mFadeAnimTags = fadeAnimateTags;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
setup(view, context, cursor);
}
private void setup(View view, Context context, Cursor cursor) {
final String id = cursor.getString(4);
if (LOCAL_LOGV) Log.v(TAG, String.format("Create item for %s. Received view: %s", id, view.toString()));
view.setTag(id);
final TextView dateText = (TextView) view.findViewById(R.id.date);
final TextView timeText = (TextView) view.findViewById(R.id.time);
final TextView title = (TextView) view.findViewById(R.id.title);
final TextView amount = (TextView) view.findViewById(R.id.amount);
final Date date = new Date(cursor.getLong(0));
title.setText(cursor.getString(1));
dateText.setText(dFormat.format(date));
timeText.setText(tFormat.format(date));
amount.setText(String.format("%d Ft", cursor.getInt(2)));
if (cursor.getInt(3) == 1) {
timeText.setTextColor(Color.LTGRAY);
title.setTextColor(Color.LTGRAY);
dateText.setTextColor(Color.LTGRAY);
amount.setTextColor(Color.LTGRAY);
} else {
timeText.setTextColor(Color.BLACK);
title.setTextColor(Color.BLACK);
dateText.setTextColor(Color.BLACK);
amount.setTextColor(Color.BLACK);
}
if (mFadeAnimTags.contains(id)) {
view.setAnimation(AnimationUtils.loadAnimation(context, R.anim.fade));
mFadeAnimTags.remove(id);
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.expense_list_item, parent, false);
setup(view, context, cursor);
return view;
}
Dónde ¿Estás comenzando la animación? Creo que debería estar en el método getView() del Adaptador. – manelizzard
empiezo allí. Código agregado a la pregunta. – gmate
¿Ha intentado crear nuevos objetos de animación cada vez que "configura" la fila? Tal vez porque está utilizando un método estático, siempre hace referencia a la misma animación y cambia de una fila a otra. – manelizzard