gpt4 book ai didi

java - android数据库的交换id

转载 作者:行者123 更新时间:2023-12-01 08:54:47 26 4
gpt4 key购买 nike

如果我想交换 Android 数据库的内容,该怎么做,如下所示:

之前

1     hello    world
2 Android Nougat

之后

1     Android  Nougat
2 hello world

最佳答案

您不需要更改数据库中的位置。您需要向数据库添加额外的 int 值(而不是 id)。并根据新的位置改变这个值。对于第一个对象,您将其设置为 2;暂时 - 1. 当您从数据库中检索数据时,您只需根据该值对其进行排序即可。

示例

String orderBy =  "POSITION ASC";
Cursor cursor = database.query(TABLE_NAME, logTableColumns, null, null,
null, null, orderBy);

关于java - android数据库的交换id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42110200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com