public void removeToDo(){
myItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
ObjectAnimator anim = ObjectAnimator.ofFloat(view, View.ALPHA, 0);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
items.remove(position);
itemsAdapter.notifyDataSetChanged();
}
});
anim.start();
return true;
}
});
}
是的它漂亮地消失了,但问题是当我添加一个新项目时它重新使用淡出该项目的行,结果是我在添加新项目但没有文本时会有一个新行。
http://i.stack.imgur.com/o6wPz.jpg
请帮助我只是一个新手:)
答案 0 :(得分:2)
试试这个解决方案。 ObjectAnimator
不可靠,请使用Animation
代替此。
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, final View view, final int position, long id) {
final Adapter adapter = (Adapter) parent.getAdapter();
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(500);
fadeOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
adapter.pointItems.remove(position);
adapter.notifyDataSetChanged();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
view.startAnimation(fadeOut);
return true;
}
});