在android中的SQLite数据库中插入数组

Har*_*eet 8 sqlite android arraylist

我想在数据库中保存工作日,所以我想通过为每天分配int值来存储它.即

1 - >选中, 0 - >未选中.

星期一= 0/1

星期二= 0/1

.....

星期日= 0/1.

但这将在DB中生成 7列.所以我想如果我将它存储在一个数组中并检索值以供进一步使用,是否有人可以帮助我.我正在通过互联网阅读一些例子,但没有轻易得到它.

Avi*_*nku 10

要在一列中插入7个值,您可以使用这样的逗号分隔符

其中Total_Score_P1是一个字符串数组

//字符串数组

String[]  Total_Score =  new String[] { p1e1,p1e2,p1e3,p1e4,p1e5,p1e6 };


// Convderting it into a single string 

String result_ScoreP1 = ("" + Arrays.asList(Total_Score_P1)).
             replaceAll("(^.|.$)", "  ").replace(", ", "  , " );
Run Code Online (Sandbox Code Playgroud)

result_ScoreP1将是

//输出

result_ScoreP1 = "p1e1,p1e2,p1e3,p1e4,p1e5,p1e6";
Run Code Online (Sandbox Code Playgroud)

将它作为单个字符串插入数据库中,并在再次检索时将其中的部分删除

//一个字符串数组列表

//查询已解雇

public ArrayList<String> rulTable(String id) {
        // TODO Auto-generated method stub
        ArrayList<String> Ruleob = new ArrayList<String>();

        Cursor c_rule;

        try
        {
            c_rule = db.query(NameTable, new String[]{
                    columns1        
            },
            Rule_COurseID + "=" + id ,
                              null, null, 
                              null, null, null);

            c_rule.moveToFirst();

            // if there is data available after the cursor's pointer, add
            // it to the ArrayList that will be returned by the method.
            if (!c_rule.isAfterLast())
            {
                do
                {

                    Ruleob.add(c_rule.getString(0));

                }
                while (c_rule.moveToNext());
            }

            // let java know that you are through with the cursor.
            c_rule.close();
        }
        catch(Exception e)
        {


        }
        return Ruleob;


    }


//list to get elements 

 ArrayList<String>  ListOne = new ArrayList<String>();

ArrayList<String> row ;

    try{
// received values
        row = db.TheTable(id);
        String r1 = row .get(0);

}

catch(Exception e)

{

}


 StringTokenizer st2 = new StringTokenizer(r1, "||");

            while(st2.hasMoreTokens()) {
            String Desc = st2.nextToken();
               System.out.println(Desc+ "\t" ); 
            ListOne.add(Desc); 

//   
            }
Run Code Online (Sandbox Code Playgroud)


Moh*_*ikh 5

您可以使用二进制整数1 =选择0 =未选中(1111111)(0000000)

总共7天所以索引0 =星期一,1 =星期二,2 =星期三,3 =星期四,4 =星期五,5 =星期六,6 =星期日......依此类推......

这里1111111表示全天选中,0000000全天未选中,0001000仅选择星期四.