I am creating a quiz app where in it asks a question and gives users options.For options I have used RadioButton So what I want is that once the user clicked any one of the options it should not allow any other options to be clicked but the problem is that it can be still clicked.if possible please write the code.Thanks!
private int Question_no=0;
private Boolean Boolean_Var=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question1);
String[] Question_Array = getResources().getStringArray(R.array.Question1);
TextView Questions = (TextView) findViewById(R.id.Question);
Questions.setText(Question_Array[Question_no]);
String[] Radio_Button1_Array = getResources().getStringArray(R.array.Option_1);
RadioButton Radio_Button1 = (RadioButton) findViewById(R.id.radioButton1);
Radio_Button1.setText(Radio_Button1_Array[Question_no]);
String[] Radio_Button2_Array = getResources().getStringArray(R.array.Option_2);
RadioButton Radio_Button2 = (RadioButton) findViewById(R.id.radioButton2);
Radio_Button2.setText(Radio_Button2_Array[Question_no]);
findViewById(R.id.MenuButton).setVisibility(View.INVISIBLE);
findViewById(R.id.NextButton).setVisibility(View.INVISIBLE);
}
public void On_RadioButton1_Click (View view)
{
if (Boolean_Var == false) {
String[] CorrectAns_Array = getResources().getStringArray(R.array.Answer1);
String CorrectAns = CorrectAns_Array[Question_no];
String[] Answer_Array = getResources().getStringArray(R.array.Option_1);
String Answer = Answer_Array[Question_no];
if (Answer.equals(CorrectAns)) {
RadioButton Right_Ans = (RadioButton) findViewById(R.id.radioButton1);
Right_Ans.setTextColor(Color.GREEN);
AnswerSubmitted();
} else {
RadioButton Wrong_Ans = (RadioButton) findViewById(R.id.radioButton1);
Wrong_Ans.setTextColor(Color.RED);;
GreenTick();
AnswerSubmitted();
}
}
Boolean_Var = true;
}
public void On_RadioButton2_Click(View view)
{
if(Boolean_Var==false)
{
String[] CorrectAns_Array = getResources().getStringArray(R.array.Answer1);
String CorrectAns = CorrectAns_Array[Question_no];
String[] Answer_Array = getResources().getStringArray(R.array.Option_2);
String Answer = Answer_Array[Question_no];
if(Answer.equals(CorrectAns))
{
RadioButton Right_Ans = (RadioButton) findViewById(R.id.radioButton2);
Right_Ans.setTextColor(Color.GREEN);
}
else
{
RadioButton Wrong_Ans = (RadioButton) findViewById(R.id.radioButton2);
Wrong_Ans.setTextColor(Color.RED);
GreenTick();
}
}
Boolean_Var=true;
AnswerSubmitted();
}
public void GreenTick()
{
String[] Answer1_Array = getResources().getStringArray(R.array.Option_1);
String Answer1 = Answer1_Array[Question_no];
String[] Answer2_Array = getResources().getStringArray(R.array.Option_2);
String Answer2 = Answer2_Array[Question_no];
String[] Answer3_Array = getResources().getStringArray(R.array.Option_3);
String Answer3 = Answer3_Array[Question_no];
String[] The_CorrectAns_Array = getResources().getStringArray(R.array.Answer1);
String The_CorrectAnsIs = The_CorrectAns_Array[Question_no];
if(The_CorrectAnsIs.equals(Answer1))
{
Button Option_with_CorrectAns = (Button) findViewById(R.id.radioButton1);
Option_with_CorrectAns.setTextColor(Color.GREEN);
}
else if(The_CorrectAnsIs.equals(Answer2))
{
Button Option_with_CorrectAns = (Button) findViewById(R.id.radioButton2);
Option_with_CorrectAns.setTextColor(Color.GREEN);
}
else if(The_CorrectAnsIs.equals(Answer3))
{
Button Option_with_CorrectAns = (Button) findViewById(R.id.radioButton3);
Option_with_CorrectAns.setTextColor(Color.GREEN);
}
else
{
Button Option_with_CorrectAns = (Button) findViewById(R.id.radioButton4);
Option_with_CorrectAns.setTextColor(Color.GREEN);
}
}
public void AnswerSubmitted()
{
findViewById(R.id.MenuButton).setVisibility(View.VISIBLE);
findViewById(R.id.NextButton).setVisibility(View.VISIBLE);
}
}