Android中List列表交换项目位置

时间:2020-11-12 13:58:39   收藏:0   阅读:16

更换项目位置

利用集合的更换函数 swap()

Collections.swap(lstApps, frmIndex, toIndex);

移动项目到指定位置,其他所有项目后移

要实现这个没有现成的方法可用,上面的swap只会下拉交换两个项目,中间的项目索引不会发生变化
这里分三步实现

String strApp = lstApp.get(frmIndex);
lstApp.remove(strApp);
lstApp.add(toIndex, strApp);
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!