Я написал XML для приложения-викторины.
Будет (10) вопросов, несколько RadioGroup и несколько CheckBox, но типы вопросов не будут располагаться в любом порядке. Итак, 1-я радиогруппа, 2-й флажок, 3-я, 4-я и 5-я радиогруппа, 6-я и 7-я флажки и т. Д.
Очевидно, что RadioGroup имеет только один правильный ответ, а CheckBox имеет два или три правильных ответа.
Я хочу создать кнопку «ПРОВЕРИТЬ ВИКТОРИНУ», которая отображает сообщение в верхней части прокручиваемой викторины с правильным числом, а также отображение большого красного «X» в красном цвете перед каждым неправильным ответом.
Я не уверен, с чего начать Java-код в моем java-файле MainActivity.
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>