【问题标题】:Android Development: Implementing MCQ quiz appAndroid 开发:实现 MCQ 测验应用
【发布时间】:2014-03-15 11:07:16
【问题描述】:

我是 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"}, 
    };

所以每一行基本上都是一个新问题,有自己的一组可能的答案。

至于界面,有一个显示问题的文本视图。有四个按钮显示每个答案。你点击一个按钮来回答。然后显示下一个问题。

    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 链接到应用程序吗?

我还希望能够提出包含一些图片的问题。如何做到这一点?请通过向我指出一些好的资源来帮助我。非常感谢!

【问题讨论】:

    标签: java android arrays database sqlite


    【解决方案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(); 
                }
            }
    

    【讨论】:

    • 非常感谢!关于如何使用数据库的任何想法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多