Saving ArrayList in SQLite database in Android

后端 未结 7 1711
臣服心动
臣服心动 2020-12-04 18:11

I\'ve been working with SQLite on android and I would like to add an arraylist to a column in a table, and then fetch the data back as an arraylist. The arraylist is a list

7条回答
  •  囚心锁ツ
    2020-12-04 18:47

    There is an easier way that do such thing in completely another way. you can make an string that consists of all your array values. for that make an StringBuilder and append the values continuously and offcource with a separator (like a simbole you which you won't use in your array values . for example virtual '|' . in code for example :

    double[] mylist = new double[]{23, 554, 55};
        StringBuilder str = null;
        str = new StringBuilder();
    
        for(int i=0;i

    when you want to fetch them and use the values. get the column from database pure it to String and with the splite() opration pure each values of array in a column of array than u can easily use it :)

    lets do it in code :

    String str = db.getdata();
        String[] list = str.split("|");
    

    with a simple convert you can use them as double;

    double mydouble = Double.parsDouble(list[1].toString());
    

    maybe it is not standard but it is helpfull, hope help ;)

提交回复
热议问题