I wrote a sample script to split the number list added in one by one into a local SQLite db.
The code
Dbhelper mdbheloper;
String numberlist = "1234,1234,1234,1234,1234,1234,1234,1234,1234";
int splitNumber = 3;
ArrayList<String> splitList = new ArrayList<String>(Arrays.asList(numberlist.split(",")));
if (splitList.size() % splitNumber != 0) {
Toast.makeText(getApplication,"Number of elelemnts not divisable by split number",1000).show();
} else {
Arraylist add_value = new Arraylist;
for (int i = 0; i < splitList.size(); i += splitNumber) {
System.out.print(((i / splitNumber) + 1) + " group of " + splitNumber +": ");
for (int j = 0; j < splitNumber; j++) {
System.out.print(splitList.get(i + j) +", ");
add_value.add(splitlist.get(i+j);
}
System.out.println();
// Added local db Sqlite
mdbheloper.insert_value(""+add_value);
add_value.remove(splitlist.get(i+j)) // error on this line
}
}
The output
1 group of 3: 1234, 1234, 1234,
2 group of 3: 1234, 1234, 1234,
3 group of 3: 1234, 1234, 1234,
but the issue is first group value will save on local db and another group value could not been save on one by one its save on overall numberlist values
How to overcome this programs? how will you remove the arraylist First added 1 group one value then
remove 1 group of 3: 1234,1234,1234 then
added 2 group of 3:1234,1234,1234 then removed its like cycle process to added local storage local db given me solution.
row id number group
1 [1234,1234,1234]
2 [1234,1234,1234]
3 [1234,1234,1234]
to store on local database.
Aucun commentaire:
Enregistrer un commentaire