Kezlyr Kezlyr - 1 year ago 84
Java Question

Android Quiz App - Make Questions Random and Dynamic

I am working on building a quiz app for Android. Once completed, the app with have around 500 questions, existing in multiple categories.

I can get the questions to work fine, but only in one instance: the questions are linear, meaning that they always appear in the same order and the question always has the same answers in the same order (so, for example, Question 1 always has Answers A, B, and C, Question 2 always has Answers D, E, F, etc.) I know the reason for this since I'm just swapping textviews, basically, but only because I don't know how to do what I'm trying to do.

  1. I want the questions within each set to go in a random order without duplicates. In a previous project, to accomplish something similar I created an integer that would generate a random value and then check to see if that value has been used already. However, that would be incredibly memory-inefficient and since I'm working on an Android app and not a PC one, that's too important to overlook.

  2. I want each question to have random answers, other than the correct one, chosen from a pool of possible answers. So, for example, if I were to ask something like "Who ruled Britain from 1810-1820" (no actual idea on the answer), I'd want one answer to be the correct one and the other two or three to be taken from a pool of 10 European rulers. Additionally, I want the placement of the correct answer to be dynamic, so it isn't always in the same spot (so people don't just memorize the question and it's answer's location).

As of now, the questions are just in a java file since I'm still in the pre-alpha stage, but I plan on moving it to a SQLite database once I get the framework for the project figured out.

Answer Source

My suggestion is you should randomize the order of the quiz's array with an integer array that contain numbers from 0 to 499. all questions will shown but not in same order. to do this, see this post: Random shuffling of an array

the second case, if I'm in your place, I will make an array of the answers, put random answers, and take a random number from 0 to 3 for the index of the right answer and



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download