Hey. I need to write an application where questions with multiple-choice questions will be asked (tests, in short). It just puzzled me a bit, but where is the best place to store the answers and the questions themselves? Create a file, use SQLlite, or even in Strinq.xml (although it seems that this is not the most desirable).

If you use SQLlite, then tell me, let's say, I will do db.execSQL(yourSql) and fill the database with my questions, but where will I get these questions from to fill them in the database. Where to store them initially in this case. (There will be no internet connection) :) Is it possible that when downloading the application, a dump is downloaded, if so, where you can read about it.

Please advise, based on your experience.

    3 answers 3

    I solved a similar situation like this:

    1. We put some XML file with questions in res / xml
    2. When you first start the XML parsing and add questions to SQLite
    3. Then we work all the time with SQLite

    Of course there is another option:

    1. We create SQLite databases (the benefit of clients including a lot of people), we put the resulting database in res / asset

    2. When you first start, we copy the database from assets to the default location (what Context.getDatabasePath() returns is something like / data / data / [my package] / databases

    3. Then everything is as usual
    • Tell me, please, why download questions from XML to SQLite, if you can get them from XML if necessary? Is there any reason? - rumnakl

    I propose to do in the database. Looking for such tables

     "вопросы" -id -текст вопроса -тип(один с многих, несколько с многих, да-нет) -подсказка "ответы" -id -id_вопроса -текст_ответа -правильный/неправильный 

    By question id, you can select answers to it by one request and display them. You can create another table "topics" and in the table of questions register the number of topics. If it were tickets, then the topic could be the "ticket number" (it is assumed that there are several questions in the ticket).

    • Thank you very much for the advice. Questions and answers will be initially, if I make it into the database (as far as I understand you mean SQLlite), then I initially have to write them there since the user will only read from there, not add. As far as I understand from the documentation, SGL Light is mainly used to store user settings? - Sever
    • You can use the base (and not just one) to store everything you need. Custom settings are simply one of the varieties of application data. - KoVadim

    It means this: for storing user settings it is preferable to use the built-in Setting mechanism. And here is just SQLite and is intended for storing the application you need to work. The database is filled when you first start the application without any problems at all: you need the SQLiteOpenHelper class in the onCreate method onCreate(SQLiteDatabase db) simply execute the necessary SQL inserts via db.execSQL(yourSql) and everything will be fine.

    • Thank you very much, then tell me, please, I still have this, let's say I will do db.execSQL (yourSql) and fill the database with my questions, but from where I will take these questions in order to fill them in the database. Where to store them in this case. (There will be no internet connection) :) - Sever
    • Everything's possible. As a simple option, simply writing SQL instructions (constants) in code and executing them. You can register the questions in the file and read it. Try to make constants to begin with - vitaly_gashock
    • How to understand constants? There are more than 1000 questions, say, 4000 answers. Create so many constants? - Sever
    • Well, I did not think that you have so many questions, honestly. So I advised constants - vitaly_gashock
    • I did not doubt your competence at all. I am very grateful, to you, for helping! Then I think it is better to create a file with all the questions and answers. And during the first run, create a label into which to insert everything from this file? - Sever