
请帮帮我朋友
解决方法 试试这个,它在我的应用程序中与我合作,在您的适配器类中,将此代码放在下面,
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
Adapteris 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_Listis name of recyclevIEw.
按照以下步骤 *** 作,如果您发现任何问题或者无法翻转项目,请直接告诉我……
看到这个GIF
总结以上是内存溢出为你收集整理的android – 如何在Recycler视图中将项目从一个部分交换到另一个部分,反之亦然?全部内容,希望文章能够帮你解决android – 如何在Recycler视图中将项目从一个部分交换到另一个部分,反之亦然?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)