Created
June 16, 2017 19:11
-
-
Save bilijo/fc7f4a8abeb4e54e1e657c9bb9f0a73d to your computer and use it in GitHub Desktop.
checkboxes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*************************** Question 3 ************************************* | |
//define an instance of checkboxes linked to question 3 | |
Button btn3 = (Button) findViewById(R.id.button_check_Q3); | |
final CheckBox checkBox1 = (CheckBox) findViewById(checkbox3_1); | |
final CheckBox checkBox2 = (CheckBox) findViewById(checkbox3_2); | |
final CheckBox checkBox3 = (CheckBox) findViewById(checkbox3_3); | |
final CheckBox checkBox4 = (CheckBox) findViewById(checkbox3_4); | |
// add clicklistener to the button which is devoted to check the selected answer for question 3 | |
btn3.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// Get the checked Radio Button ID from Radio Group | |
//int selectedRadioButtonID ; | |
// Check which checkbox was clicked | |
if (checkBox1.isChecked()) { | |
rightAnswers++; | |
} | |
if (checkBox2.isChecked()) { | |
wrongAnswers++; | |
} | |
if (checkBox3.isChecked()) { | |
rightAnswers++; | |
} | |
if (checkBox4.isChecked()) { | |
rightAnswers++; | |
} | |
if (rightAnswers ==0 && wrongAnswers ==0){ | |
//message if no checkboxes selected | |
Toast.makeText(MainActivity.this, "Nothing selected from checkboxes.", | |
Toast.LENGTH_LONG).show(); | |
} | |
Log.v("MainActivity", "rightAnswers: " + rightAnswers); | |
} | |
}); | |
//****************************************************** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment