Android:如何实施测验应用

pog*_*ogo -3 android android-layout

我正在尝试实现一个Android应用程序,其中包含用户可以进行测验的部分.由于我是Android应用程序开发的新手,我想在布局方面有一些关于如何实现测验部分的建议

我有一组问题,每个问题都有各自的答案选择,我可以从我的API中检索.

执行此操作的最佳易于实施的方法是什么?我需要逐页显示每个问题(Q1 - > Q2 - > ...).

我是否会生成一组片段?或者我是否以某种方式使用RecyclerView为每个问题生成每个页面?

任何指导将不胜感激,谢谢!

NoC*_*uxe 5

这是一个广泛的问题,但这里有一些快速的想法,让你开始.

在我的头顶,你可以有一个名为QuestionActivity(或任何你想要的)的活动,这将是显示问题的主要容器.然后,您将有一个QuestionFragment,它将显示在QuestionActivity中.每次要显示新问题时,都要调用Fragment的newInstance()方法,每次都在Bundle中传入适当的数据以填充Fragment的布局,然后使用片段事务替换Activity中的Fragment.

至于Fragment本身,你可以做一个LinearLayout,顶部的TextView显示问题,下面是一组RadioButtons,显示一些多选项,然后是一个提交Button,用户可以使用提交他的答案.那么你当然会收到这些东西的所有点击事件,以确定选择了哪个答案等.

你的QuestionFragment布局可能会以这样的方式开始......

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.david.timedtask.QuizActivity">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/quiz_question"
            android:id="@+id/textView"
            android:layout_gravity="center_horizontal"
            android:paddingBottom="100dp"/>

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/option_one"
            android:id="@+id/radioButton" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/option_two"
            android:id="@+id/radioButton2" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/option_three"
            android:id="@+id/radioButton3" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/option_four"
            android:id="@+id/radioButton4" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/submit_button"
            android:id="@+id/button"
            android:layout_marginTop="50dp"/>
    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这会产生一个看起来像这样的结果......

在此输入图像描述

当然这都是非常基本的,但同样,你的问题相当广泛.有很多文档可以向您展示如何实际编写所有这些内容并将它们放在一起,但希望这会让您开始.

祝好运!