내 ListView에서 새 항목에 애니메이션을 적용하려고합니다. 나는 id-s가 안정적이어서 어떤 요소가 움직일 지 정확히 알고있다. 문제는 ListView의 재활용 메커니즘에서 비롯됩니다. 내가 최근에 삽입 된 요소를 알고있는 경우 View에서 startAnimation을 호출합니다. 그런 다음보기가 재활용되어 다른 데이터로 채워집니다. 잘못된 행에 애니메이션을 적용하는 UI가 발생합니다. 어떤 시점에서보기는 올바른 데이터를 보유하고 있었지만 재활용되었습니다. 나는 logcat을 통해이를 확인했다. 이 문제를 해결할 방법이 있습니까?ListView의 목록 항목 애니메이트
편집 :
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;
}
당신이 애니메이션을 시작? 나는 그것이 어댑터의 getView() 메소드에 있어야한다고 생각한다. – manelizzard
거기서 시작하겠습니다. 코드가 질문에 추가되었습니다. – gmate
행을 "설정"할 때마다 새 애니메이션 객체를 만들려고 했습니까? 어쩌면 정적 메서드를 사용하기 때문에 항상 동일한 애니메이션을 참조하고 한 행에서 다른 행으로 변경됩니다. – manelizzard