MvpApp
MvpApp copied to clipboard
数据库里的记录可以这样交换顺序
@Override
public void swap(int fromPos, int toPos, List<NewsTypeInfo> list) {
NewsTypeInfo fromInfo = list.get(fromPos);
NewsTypeInfo toInfo = list.get(toPos);
NewsTypeInfo tem = fromInfo;
//要重写创建对象,不能去改变源对象,因为源对象在多处使用到
fromInfo = new NewsTypeInfo(tem.getId(), toInfo.getName(), toInfo.getTypeId());
toInfo = new NewsTypeInfo(toInfo.getId(), tem.getName(), tem.getTypeId());
update(fromInfo);
update(toInfo);
}
嗯,这样应该会比我之前写法好
@Lingyuezhixing 有没有更详细点的源码