【问题标题】:How Can Add ArrayList into a SQLite Database?如何将 ArrayList 添加到 SQLite 数据库中?
【发布时间】:2018-07-09 22:20:34
【问题描述】:

我有我想在sqlite 的一列中添加的整数数组列表 数据库,

我通过contentValues 这样做:

contentValues.put(Tag.REPORT_LATITUDE_LIST, report.getLatitudes());

首先!数据库table 中这个columntype 是什么?

如何从sqlite 获取这些arrayList 数据?

【问题讨论】:

    标签: android sqlite arraylist


    【解决方案1】:

    您可以将对象序列化为 JSON,以这种格式将其存储为字符串,然后在读取时反序列化。

     contentValues.put(Tag.REPORT_LATITUDE_LIST, new Gson().toJson(report.getLatitudes()));
    

    您需要将 Gson 添加到您的 gradle 依赖项中。

    dependencies {
    implementation 'com.google.code.gson:gson:2.8.5'
    

    }

    【讨论】:

    • 它将被存储为一个字符串
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多