我在活动中有一个ListView。在每个列表项中都有一个文本和一个CheckBox。单击CheckBox,我想从ListView中删除该项目,并希望添加一个动画,如向下滑动或淡出,然后删除。
任何帮助?
答案 0 :(得分:7)
看看我的回答
protected void removeListItem(View rowView, final int positon) {
// TODO Auto-generated method stub
final Animation animation = AnimationUtils.loadAnimation(rowView.getContext(), R.anim.splashfadeout);
rowView.startAnimation(animation);
Handler handle = new Handler();
handle.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
array.remove(positon);
adapter.notifyDataSetChanged();
animation.cancel();
}
}, 1000);
}
在onItem点击ListView
中调用removeListItem(View rowView, final int positon)
方法
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView <? > parent, View rowView, int positon, long id) {
// TODO Auto-generated method stub
Toast.makeText(rowView.getContext(), "" + positon, Toast.LENGTH_LONG).show();
removeListItem(rowView, positon);
}
});
和res / anim / splashfadeout.xml
<?xml version="1.0" encoding="utf-8" ?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="2000" />
动画ListView hear
的完整源代码答案 1 :(得分:-1)
你应该在你的适配器类的复选框上实现onClickListener,并在那里设置textview GONE或Invisible的可见性,或从你的列表中删除项目和调用方法notifyDataSetChanged()....