mardi 6 octobre 2015

create table with strings and arrays in sqlite by developing in android

I would like to create a sqlite database starting from some input data contained in a xml file. The xml file contains items like:

<item>rome line1 1 3 4 5 ...</item>

I would like to have a table with three columns, the first two are string columns, the third one an array of integers (or strings). Is it possible to realise this in android studio? How do I put the values to initialize the table?

here is a sample of how I want the table to be:

    public static abstract class FeedEntry implements BaseColumns {
    public static final String TABLE_NAME = "entry";
    public static final String COLUMN_NAME_ENTRY_ID = "entryid";
    public static final String COLUMN_NAME_TITLE = "title";
    public static final String[] COLUMN_NAME_SCHEDULE = "schedule";
}

Here is the function to initialize the table

        String[] myArray = res.getStringArray(R.array.my_array);
    for (String item : myArray) {
        String[] split = item.split("\\s+");

        values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID, split[0]);
        values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE, split[1]);

        for (int i = 2; i < myArray.length - 2; i++) {
            values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_SCHEDULE, Integer.parseInt(split[i]));
        }
        db.insert(FeedReaderContract.FeedEntry.TABLE_NAME, null, values);

    }

here is the array.xml file

<?xml version="1.0" encoding="utf-8"?>

<string-array name="my_array">

    <item>rome line1 1 3 5 7 11 190</item>


</string-array>

However, in what I have now there are some incompatible types, for example I am not able to put an array of integers in values, when I initialize the table.

Aucun commentaire:

Enregistrer un commentaire