u3l*_*u3l 2 android listview swipe android-cardview android-recyclerview
我需要能够在RecyclerView没有用户实际滑动的情况下以编程方式关闭 a 中的项目(相反,我想在他们点击卡片中的按钮时关闭该项目)。我见过的很多库似乎只支持实际的滑动。
我试过使用现有的库,只是MotionEvent通过以编程方式创建自己的滑动来模拟一个,但这会干扰另一个水平滑动侦听器,所以我想知道还有什么办法可以做到,理想情况下,RecyclerView如果有人知道如何为ListView,而不是我可以尝试去适应这一点。
我已经查看了这个库以及其他库以获取灵感,但我无法弄清楚如何以编程方式触发滑动。
小智 5
使用ListView或RecyclerView自定义适配器,并notifyDataSetChanged在从数据列表中删除项目后调用:
private void removeListItem(View rowView, final int position) {
Animation anim = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
anim.setDuration(500);
rowView.startAnimation(anim);
new Handler().postDelayed(new Runnable() {
public void run() {
values.remove(position); //Remove the current content from the array
adapter.notifyDataSetChanged(); //Refresh list
}
}, anim.getDuration());
}
Run Code Online (Sandbox Code Playgroud)