我是Android应用程序开发的初学者,正在尝试构建一个简单的MCQ测验应用程序。
我所做的是制作一个二维数组并存储问题,可能的答案和正确的解决方案。
在此图片中可以看到表格中的样本:
所以我命名了我的数组数据库。创建此数组的代码名为database [] []如下:
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"},
};
所以每一行基本上都是一个新问题,有一套可能的答案。
对于界面,有一个显示问题的textview。有四个按钮显示每个答案。您单击按钮进行回答。然后显示下一个问题。
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]);
现在我的问题是,如果我想让这个应用程序更通用,那么使用其他方法来实现这些问题会更好吗?我的意思是也许我可以将问题存储在文本文件中?或者我应该使用SQLite?我不知道利弊,基本上有什么限制?
我有pdf格式的问题,我可以用它以某种方式将这些问题直接从pdf链接到应用程序吗?
此外,我希望能够提出包含一些图片的问题。怎么实现呢?请指点我一些好的资源来帮助我。非常感谢!
答案 0 :(得分:1)
以下代码有助于在您的应用中打开pdf
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();
}
}