Reputation: 125
I am a beginner in android app development and was trying to build a simple MCQ quiz app.
What I did was make a two dimensional array and stored the questions, possible answers and the correct solution in it.
A sample from the table can be seen in this image:
So I named my array database. The code for creating this array called database[][] is below:
database = new String[][]{
{"Before marking the finishing line on a running track, a groundsman measures out its 100 m length. Which instrument is the most appropriate for this purpose?",
"measuring tape","metre rule","30 cm ruler","micrometer", "A"},
{"A car of mass 1500 kg travels along a horizontal road. It accelerates steadily from 10 m / s to 25 m / s in 5.0 s. What is the force needed to produce this acceleration?",
"300N","500N","4500N","D.7500N", "C"},
{"A lorry of mass 10 000 kg takes 5000 kg of sand to the top of a hill 50 m high, unloads the sand and then returns to the bottom of the hill. The gravitational field strength is 10 N / kg. What is the overall gain in potential energy?",
"250 000 J","750 000 J","2 500 000 J","D.7 500 000J", "C"},
{"A liquid-in-glass thermometer contains mercury. Which physical property of the mercury varies with temperature, enabling the thermometer to operate?",
"mass","melting point","resistance","volume", "D"},
{"Thermal energy of 12 000 J is supplied to a 2.0 kg mass of copper. The specific heat capacity of copper is 400 J / (kg °C). What is the rise in temperature?",
"15 Degree C","30 Degree C","60 Degree C","100 Degree C", "A"},
};
So each row is basically a new question with its own set of possible answers.
As for the interface, there is a textview that shows the question. There are four buttons which show each of the answers. You click on a button to answer. Then the next question is showed.
textviewQuestion.setText(database[x][y]);
buttonA.setText("A. " + database[x][1]);
buttonB.setText("B. " + database[x][2]);
buttonC.setText("C. " + database[x][3]);
buttonD.setText("D. " + database[x][4]);
Now my question is, if I want to make this app more versatile is it better to use other ways to implement the questions? I mean maybe I can store the questions in a text file? Or should I use SQLite? I don't know the pros and cons and basically what are the limitations?
I have the questions in pdf format, so can I use that to somehow link those questions directly from the pdf to the app?
Also I want to be able to ask questions which include some images. How to achieve that? Please help me out by pointing me to some good resources. Thanks a lot!
Upvotes: 1
Views: 1924
Reputation: 272
following code is help for opening pdf in your app
File pdfFile = new File(path);
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(uractivity.this, "File does not exist", Toast.LENGTH_LONG).show();
}
}
Upvotes: 1