Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something vaguely like this.</p> <p>Add to res/values/<i>&lt;yourchoiceoffilename&gt;</i>.xml &amp; add your string references to a string-array.</p> <pre><code>&lt;resources&gt; &lt;string-array name="categories"&gt; &lt;item&gt;@string/fuel&lt;/item&gt; &lt;item&gt;@string/food&lt;/item&gt; &lt;item&gt;@string/treatment&lt;/item&gt; &lt;item&gt;@string/salary&lt;/item&gt; &lt;/string-array&gt; &lt;/resources&gt; </code></pre> <p>Create a SQLiteStatement on your database.</p> <pre><code>SQLiteDatabase db = ...; SQLiteStatement insert = db.compileStatement("INSERT INTO categories (yourcolumnnamehere) VALUES (?)"); //process each string for (String category : getResources().getStringArray(R.array.categories)) { insert.bindValue(1, category); long id = insert.executeInsert(); // In case you care about the row id. } </code></pre> <p><b>Edit</b>: And, consider doing something <i>like</i> following to your class (I've probably left a bug or two in there, but you should get the gist of it):</p> <pre><code>private static class DatabaseHelper extends SQLiteOpenHelper { ... // Replace 'yourcolumnnamehere' with whatever your column is actually named. private static final String INSERT_CATEGORY = "INSERT INTO categories (yourcolumnamehere) VALUES (?)" ... ... private final String[] mCategories; DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); mCategories = context.getResources().getStringArray(R.array.categories); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); // Here you create the SQLiteStatement that will be used // to add categories. The values are stored in mCategories. SQLiteStatement statement = db.compileStatement(INSERT_CATEGORY); for (String category : mCategories) { statement.bindValue(1, category); statement.executeInsert(); } statement.close(); db.execSQL(EXPENSES_CREATE); db.execSQL(INCOMES_CREATE); db.execSQL(BUGS_CREATE); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload