0

I am new to Android. I am doing small quiz application. I have 5 sets of JSON file like .txt files. Each set consist of 30 questions.

My requirement is select 3 questions from each JSON set. Totaly i need to display 15 questions from 5 sets. How can i take questions from all sets ?

Thanks in advance.

2 Answers2

0

Parse your 5 files to 5 diffrent ArrayList of String questions and then choose randomly 3 question from each ArrayList. to get an idea how to parse Json files you can take a look at this blog post I wrote, the example there is much more complicated but you will get the point:

Parsing Json Files

and to choose them randomly take a look at the Random class and at this post:

How can I generate random number in specific range in Android?

Community
  • 1
  • 1
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
0
  1. Read the TextFiles into a String
  2. Parse the String into a JSONObject
  3. Using the JSONObject's methods, fill an Array or a List with the questions. As you want to extract 5 questions for each file, you will need a List/Array per file.
  4. Using random numbers (See Random), extract the questions at the random index.
Community
  • 1
  • 1
snrlx
  • 4,987
  • 2
  • 27
  • 34