Database and Android doubts

2

I'm developing a project for college that is about a multiplayer Android game for questions and answers (Style Asked). In game development, I need to create a database to store the questions, their answers, and the correct option. The game accesses this database and chooses a random question. As I've never moved with database before, I have questions about how to implement this database.

    
asked by anonymous 28.10.2014 / 13:39

2 answers

1

If the game is for Android, you will need to use the SQLite database and the SQLiteMan to manage your database data more easily.

A simple example of how to structure your information would be to create a table with the following fields: _id, question, option_a, option_b, option_c, option_d, answer_d

Notes:

  • As you said the game looks like Asked , I assumed that the questions are multiple choice and there are 4 answer options (a, b, c, d) for each question with just a correct answer.
  • The _id field is used to query and display them using a CursorAdapter , so if you do not go use CursorAdapter, you do not need to use _id.
  • So, a quick step-by-step would be:

  • Install SQLite and SQLiteMan
  • Create a folder named assets in "your app path / app / src / main"
  • Open SQLiteMan, create a file meubanco.db
  • Execute the following SQL code (this table is just a suggestion, you can create the schema you think is best)

    CREATE TABLE perguntas (
        _id INTEGER PRIMARY_KEY AUTOINCREMENT,
        pergunta TEXT,
        opcao_a TEXT,
        opcao_b TEXT,
        opcao_c TEXT,
        opcao_d TEXT,
        resposta TEXT
    );
    
  • Save the file in the assets folder
  • By performing these steps, you will already have the database ready for use in your application. Then there would be the most boring part: Accessing bank information by the application.

    As you said you have never messed with databases, I suggest you take a look at the basics of Database and SQL (mainly in the part of keywords )

    Now just stick your hand in the dough and when you have more specific doubts, feel free to ask your questions here: -)

        
    16.08.2015 / 08:18
    0

    It seems to me that in this case, there are only two entities involved: questions and answers. Whether the answer is correct is not just an attribute of the answer. I'll put a "generic" SQL code, which you'll need to adapt to SQLite.

    CREATE TABLE perguntas (
      id NUMBER,
      pergunta VARCHAR(150)
    );
    CREATE TABLE respostas (
      id NUMBER,
      resposta VARCHAR(150),
      correta BOOLEAN,
      id_pergunta NUMBER
    );
    

    I hope it helps.

        
    28.04.2015 / 21:20