将ArrayList放在ContentValues中

时间:2016-07-11 13:44:34

标签: android arraylist android-contentprovider couchbase content-values

我在Android中使用couchbaselite,我想使用ContentProvider和ContentValues在我的数据库中插入文档。我的文档的一个属性是ArrayList,但是使用ConentValues我不能直接放置一个ArrayList。这是我的代码:

ContentValues valuesTour = new ContentValues();
valuesTour.put(DBFields.COLUMN_PROGRESS_PERC,completionPercentage);
valuesTour.put(DBFields.COLUMN_STEPS, new ArrayList()); //here I need to put an ArrayList
update(DBFields.CONTENT_URI, valuesTour, 1234, null);

有解决方法吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

您无法将数组直接放入数据库中。在您的代码中,您基本上保存了无用的数组地址。一个简单的解决方案是使用您自己的toString()实现或使用第三方库(即Gson)将数组转换为字符串。