I wrote the XML for a Quiz App.
There will be (10) questions, some RadioGroup and some CheckBox, but the type of questions will not be in any order. So the 1st is radiogroup, the 2nd checkbox, the 3rd, 4th, and 5th radiogroup, the 6th and 7th checkbox, etc.
The RadioGroup obviously has only one correct answer, and the CheckBox have two or three correct answers.
I want to create a "CHECK QUIZ" button, which displays a message at the top of the scrolling quiz giving the number correct, and also displaying a large red "X" in red at the front of each wrong answer.
I am not sure where to start for the Java code in my MainActivity java file.
MainActivity.java
package com.example.android.quiztest;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
import android.widget.EditText;
import android.widget.TextView;
/**
* package com.example.android.quiztest;
* This app displays a radio button and checkbox quiz, and then grades the quiz, * displaying the score and identifying the incorrect answers.
**/
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.example.android.quiztest.R.layout.activity_main);
}
}
activity_main.xml
<ScrollView 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"
tools:context="com.example.android.quiztest.MainActivity"
android:fillViewport="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/dimension_1"
android:orientation="vertical">
<EditText
android:id="@+id/name_text_view_STUDENT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/text_person_name"
android:inputType="textPersonName" />
<TextView
android:id="@+id/label_text_view_DIRECTIONS"
style="@style/HeaderTextStyle"
android:textSize="20sp"
android:layout_marginTop="@dimen/dimension_1"
android:text="@string/text_directions" />
<TextView
android:id="@+id/label_text_view_1"
style="@style/HeaderTextStyle"
android:layout_marginTop="@dimen/dimension_1"
android:text="@string/text_1" />
<RadioGroup
android:id="@+id/radioGroup_1"
style="@style/HeaderTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioButton_1a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimension_1"
android:paddingLeft="@dimen/dimension_4"
android:paddingRight="@dimen/dimension_5"
android:text="@string/text_1a"
android:textSize="@dimen/text_size_1" />
<RadioButton
android:id="@+id/radioButton_1b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimension_1"
android:paddingLeft="@dimen/dimension_4"
android:paddingRight="@dimen/dimension_5"
android:text="@string/text_1b"
android:textSize="@dimen/text_size_1" />
<RadioButton
android:id="@+id/radioButton_1c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimension_1"
android:paddingLeft="@dimen/dimension_4"
android:paddingRight="@dimen/dimension_5"
android:text="@string/text_1c"
android:textSize="@dimen/text_size_1" />
</RadioGroup>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="25dp"
android:background="#c0c0c0" />
<TextView
android:id="@+id/label_text_view_2"
style="@style/HeaderTextStyle"
android:layout_marginTop="@dimen/dimension_1"
android:text="@string/text_2" />
<CheckBox
android:id="@+id/checkBox_2a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/dimension_4"
android:paddingRight="@dimen/dimension_5"
android:text="@string/text_2a"
android:textSize="@dimen/text_size_1" />
<CheckBox
android:id="@+id/checkBox_2b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimension_1"
android:paddingLeft="@dimen/dimension_4"
android:paddingRight="@dimen/dimension_5"
android:text="@string/text_2b"
android:textSize="@dimen/text_size_1" />
<CheckBox
android:id="@+id/checkBox_2c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimension_1"
android:paddingLeft="@dimen/dimension_4"
android:paddingRight="@dimen/dimension_5"
android:text="@string/text_2c"
android:textSize="@dimen/text_size_1" />
</LinearLayout>
</ScrollView>
strings.xml
<resources>
<string name="text_button_1">check answers</string>
<string name="app_name">Quiz Test</string>
<string name="text_person_name">Type student name here.</string>
<string name="text_directions">Select ALL correct answers:</string>
<string name="text_1">1) probability distribution</string>
<string name="text_1a">1a) A smooth curve indicating the frequency distribution for a discontinuous random variable.</string>
<string name="text_1b">1b) A discontinuous dot diagram showing the frequency distribution for a random variable.</string>
<string name="text_1c">1c) A smooth curve indicating the frequency distribution for a continuous random variable.</string>
<string name="text_2">2) normal distribution</string>
<string name="text_2a">2a) A smooth double-peak bell-shaped curve symmetrical about the mean.</string>
<string name="text_2b">2b) A smooth single-peak curve </string>
<string name="text_2c">3c) A bell-shaped curve symmetrical about the mean. </string>
</resources>