Questions about database and Android

Asked

Viewed 455 times

2

I am developing a project for college that is a multiplayer game for Android of questions and answers (style Asked). In the development of the game, 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 have never handled database before, I have doubts about how to implement this database.

  • Your doubt is exactly on what part of the implementation?

  • How to insert questions in the database

  • Thinking quickly, I would create a table for the questions (question column and column with the question), a table for the wrong answers (column with the Question, column with the answer 1, column with the answer 2 and column with the Question) and a table for the right answer (column cadQuestao, column answerCerta and column codResoCerta)

  • That’s what I wanted to know?

  • You need a database editor, don’t you? Which one do you recommend?

  • The Valentina studio is good?

  • Sorry, I never used an editor, I use SQL commands myself. If you put the database on a web server, most of them use myPHP admin, you will be able to use it easily.

  • 1

    Thanks for the help!

  • If you are going to keep the data in a local database you will use Sqlite, if you want something remote, search on Webservices.

Show 4 more comments

2 answers

1

If the game is for Android, you will need to use the database Sqlite 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, opcao_a, opcao_b, opcao_c, opcao_d, answer

Remarks:

  1. As you said the game is similar to the Asked, i assumed that the questions are multiple choice and there are 4 answer options (a,b,c,d) for each question with only one correct answer.
  2. The field _id is used to make queries and display them using a Cursoradapter, so if you’re not going to use Cursoradapter, you don’t need to use _id.

So a quick step-by-step would be:

  1. Install Sqlite and Sqliteman
  2. Create a folder called Assets in "path of your project/app/src/main"
  3. Open Sqliteman, create a file meubanco.db
  4. Run the following SQL code ( this table is just a suggestion, you can create the schema you think 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
    );
    
  5. Save the file to the folder Assets

By performing these steps, you will already have the database ready for use in your application. Then came the most boring part: Access of bank information by the application.

Since you said you never messed with databases, I suggest you take a look at the basics of Database and SQL ( especially on the part of keywords)

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

0

It seems to me that in this case, there are only two entities involved: questions and answers. Whether the answer is correct or not is just an attribute of the answer. I will put a "generic" SQL code, which you will 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.