解决方法
试试这个,它在我的应用程序中与我合作,
在您的适配器类中,将此代码放在下面,
here MessageList is name of the Arraylist,
public void swap(int firstPosition,int secondPosition) { Collections.swap(MessageList,firstPosition,secondPosition); notifyItemmoved(firstPosition,secondPosition); }
Now add this small class separately,
here
Adapter
is name of the Adapter class put your adapter name
public class MovietouchHelper extends itemtouchhelper.SimpleCallback { Aadapter recycleAdapter; public MovietouchHelper(Aadapter recycleAdapter) { super(itemtouchhelper.UP | itemtouchhelper.DOWN,itemtouchhelper.LEFT | itemtouchhelper.RIGHT); this.recycleAdapter = recycleAdapter; } @Override public boolean onMove(RecyclerView recyclerView,RecyclerView.ViewHolder viewHolder,RecyclerView.ViewHolder target) { recycleAdapter.swap(viewHolder.getAdapterPosition(),target.getAdapterPosition()); return true; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder,int direction) { recycleAdapter.remove(viewHolder.getAdapterPosition()); } }
然后在你定义了recycleview的mainActivity中,
itemtouchhelper.Callback callback = new MovietouchHelper(adapter); itemtouchhelper helper = new itemtouchhelper(callback); helper.attachToRecyclerView(rv_list);
here
rv_list
is name of recycleview.
按照以下步骤操作,如果您发现任何问题或者无法翻转项目,请直接告诉我……
看到这个GIF
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。