Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import android.annotation.SuppressLint; import android.os . Bundle; import android.view.View; import android.widget.ProgressBar; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class mcqs extends AppCompatActivity
import android.annotation.SuppressLint;
import android.osBundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class mcqs extends AppCompatActivity
private TextView questionText;
private RadioGroup optionsGroup;
private TextView progressText;
private ProgressBar progressBar;
private String questions;
private String options;
private int correctAnswers;
private int currentQuestionIndex ;
private int score ;
@SuppressLintMissingInflatedId
@Override
protected void onCreateBundle savedInstanceState
super.onCreatesavedInstanceState;
setContentViewRlayout.activitymcqs;
questionText findViewByIdRidquestionText;
optionsGroup findViewByIdRidoptionsGroup;
progressText findViewByIdRidprogresstext;
progressBar findViewByIdRidprogressbar;
Initialize questions, options, and correct answers
questions getResourcesgetStringArrayRarray.questionsmcqs;
options new String
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
getResourcesgetStringArrayRarray.options
Add more options arrays as needed
;
correctAnswers new int; Adjust correct answers based on your quiz logic
loadQuestion;
optionsGroup.setOnCheckedChangeListenergroup checkedId
RadioButton selectedRadioButton findViewByIdcheckedId;
int selectedAnswerIndex optionsGroup.indexOfChildselectedRadioButton;
Check if the selected answer is correct
if selectedAnswerIndex correctAnswerscurrentQuestionIndex
score;
Toast.makeTextthis "Correct!", Toast.LENGTHSHORTshow;
else
Toast.makeTextthis "Incorrect!", Toast.LENGTHSHORTshow;
currentQuestionIndex;
if currentQuestionIndex questions.length
loadQuestion;
else
End of quiz
questionText.setTextQuiz Completed! Your score: score questions.length;
optionsGroup.setVisibilityViewGONE;
;
private void loadQuestion
questionText.setTextquestionscurrentQuestionIndex;
RadioButton optionsGroup.getChildAtsetTextoptionscurrentQuestionIndex;
RadioButton optionsGroup.getChildAtsetTextoptionscurrentQuestionIndex;
RadioButton optionsGroup.getChildAtsetTextoptionscurrentQuestionIndex;
RadioButton optionsGroup.getChildAtsetTextoptionscurrentQuestionIndex;
progressText.setTextcurrentQuestionIndex questions.length;
progressBar.setProgresscurrentQuestionIndex ;
optionsGroup.clearCheck;
I dont know why but in my string files there are qutions but the quizz ends after the first question
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started