If seperated by ","
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]));
Now the custom Class Publication
class Publication{
String field;
public void setField(String f) {
field=f;
}
public String getField() {
return field;
}
}
or
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);
}
}
Check this:
You wont be able to insert ArrayList directly into Sqlite. Instead, you could use JSONObject (org.json.JSONObject) to insert the ArrayList. Please check below and give it a shot....
//Add values to arraylist item
ArrayList<Publication> item = new ArrayList<Publication>();
item.add //add the item to array list
To insert,
JSONObject json = new JSONObject();
json.put("uniqueArrays", new JSONArray(items));
String arrayList = json.toString();
Insert the string into db.
To Read, Read the string from db as String,
JSONObject json = new JSONObject(stringreadfromsqlite);
ArrayList<Publication> items = json.optJSONArray("uniqueArrays");