1

I am trying to make A app that starts which a text view (question)and below then a drop down with list options (answers to choose) depending on the result if click that item it takes you to a different view with more question text view and drop down list views options. Finally at the end result there is something different depending on what options you choose. Make sense? looking for any source code or example on how to even get start in sure its very repetitive so anything will please guys.

Jaison Brooks
  • 5,816
  • 7
  • 43
  • 79

1 Answers1

0

Well to make the drop down list you will need to use a spinner object as detailed here and then you will need to use spinner adapter to populate this list, this may be useful.

Once a user selects an answer in your quiz, you could repopulate the same layout with a different question and answers to start the next round by changing your answerArray and using invalidate(); to redraw the view (if they get the answer wrong you'd move to a "Game Over" layout instead).

As far as storing the questions and answers goes I would suggest some sort of SQLite database. SQLite databases can be stored in the app's data directory. Android has ways of creating, editing and reading databases, check this out. Most tutorials show you how to create a database with code, but if you have a predefined database of questions to ship then you can put it in the assets folder and copy it into the app's data directory from there.

The database would store questions in one table and answers in another. By using a question id field you can show which answers belong to which question. You can also show which answers are correct using a true/false boolean field.

When the apps read the answers into the adapter you could create an answer object containing the text and also the boolean right/wrong value

public class AnswerObject{
    public String text;
    public boolean isCorrect;

    public AnswerObject(){
        this.text = "";
        this.isCorrect=false;
    }
}

Then create an object for each answer in a question and store them in an array

AnswerObject[] answers = new AnswerObject[numberOfAnswers];
for(i=0; i<answers.length; i++){
     answers[i].text = textFromDatabase;
     answers[i].isCorrect = booleanFromDataBase; 
}

I apologise for mistakes in code. I typed it by hand.

Community
  • 1
  • 1
Jack
  • 2,625
  • 5
  • 33
  • 56