如果分隔 “”
String[] strValues = str.split(",");//this is the string u saved in sqlite
/*Use asList method of Arrays class to convert Java String array to ArrayList*/
ArrayList<Publication> aList = new ArrayList<Publication>();
for(i=0; i<strValues.count(); i++)
aList.add(new Publication().setField(strValues[i]));
现在自定义类公开
class Publication{
String field;
public void setField(String f) {
field=f;
}
public String getField() {
return field;
}
}
或
for (String value: strValues) {
aList.add(new Publication(value));
}
class Publication {
private final String input;
public Publication(String input) {
this.input = input;
}
// not needed but implemented for completeness
public static Publication parse(String input) {
return new Publication(input);
}
}
检查: 你不会成为能够插入ArrayList中直接进入sqlite的。相反,你可以使用JSONObject(org.json.JSONObject)来插入ArrayList。请在下面检查,并给它一个镜头....
//Add values to arraylist item
ArrayList<Publication> item = new ArrayList<Publication>();
item.add //add the item to array list
要插入,
JSONObject json = new JSONObject();
json.put("uniqueArrays", new JSONArray(items));
String arrayList = json.toString();
Insert the string into db.
阅读,从数据库字符串,
JSONObject json = new JSONObject(stringreadfromsqlite);
ArrayList<Publication> items = json.optJSONArray("uniqueArrays");
发布UR串 – Athul
请的一个例子分享您的代码 –
你是怎么保存的数组列表?在每个字符串之后添加逗号(,)? –