Java – multiple choice test

I'm doing single - choice and multiple - choice tests

I have several questions and four answers to each question

Each answer is assigned to a radio button and I'm shuffling This is the array list I'm shuffling. Random is an array list containing items, and R1, R2, R3 and R4 are radio buttons

random.add(val);
Collections.shuffle(random);


r1.setText(random.get(0));
r2.setText(random.get(1));
r3.setText(random.get(2));
r4.setText(random.get(3));

I can display the answer in a chaotic way, but when I choose the answer, I need to show whether the answer is right or wrong

Sample question and options.
1. which language is used for android programming?
 A.PHP
 B.JAVA
 C.C
 D.C++

The correct answer is B. I need to show that the correct answer is B

How to achieve this

Editor: I tried this:

The click button of each radio button assigns the value a and compares the value with the XML value. If it is correct, it displays correctly, but when I confuse it with not working

Edit 2 XML

<Question no="1" text="Which Programming language is used in android develoment" type="SCA" noc="4" jumble="NO" correctans="PHP">
<choice a = "PHP" flag="A"> 
<choice b = "JAVA" flag="B"> 
<choice c = "C" flag="C"> 
<choice d = "C++" flag="D">

Solution

This is a somewhat naive solution, but it should work

class Question {
    String message;
    String answer;
    List<String> options; //"Java","PHP",etc
}

In your Question object, call the Map key on your radio button, do something like r1.. setText(random.get(0))

Click to do

String choice = null;
for (RadioButton rb : rBtns) {
    if (rb.isSelected) {
        choice = rb.getText(); break();
    }
}

if (choice.equals(question.getAnswer))
    return true; //correct
else
    return false; //wrong
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>