Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.dell.quizapp;
- import android.app.Activity;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- int Score = 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void displayscore(View view) {
- boolean allCorrect = Score==4;
- if (allCorrect){
- Toast.makeText(this, "Congrats!", Toast.LENGTH_SHORT).show();
- }else {
- Toast.makeText(this, "your score is " + Score + " out of 4", Toast.LENGTH_SHORT).show();
- Score=0;
- }
- }
- public void onEiffelRadioButtonClicked(View view) {
- RadioButton radioButton = (RadioButton) findViewById(R.id.eiffel);
- boolean isradioButtonChecked = radioButton.isChecked();
- if (isradioButtonChecked) {
- Score++;
- }
- }
- public void onBkhalifaRadioButtonClicked(View view) {
- RadioButton radioButton = (RadioButton) findViewById(R.id.burj_khalifa);
- boolean isradioButtonChecked = radioButton.isChecked();
- if (isradioButtonChecked) {
- Score--;
- }
- }
- public void onChinaRadioButtonClicked(View view) {
- RadioButton radioButton = (RadioButton) findViewById(R.id.china);
- boolean isradioButtonChecked = radioButton.isChecked();
- if (isradioButtonChecked) {
- Score++;
- }
- }
- public void onRussiaRadioButtonClicked(View view) {
- RadioButton radioButton = (RadioButton) findViewById(R.id.russia);
- boolean isradioButtonChecked = radioButton.isChecked();
- if (isradioButtonChecked) {
- Score--;
- }
- }
- public void Checkboxes(View view) {
- final CheckBox checkBox1 = (CheckBox) findViewById(R.id.denmark);
- final CheckBox checkBox2 = (CheckBox) findViewById(R.id.portugal);
- final CheckBox checkBox3 = (CheckBox) findViewById(R.id.italy);
- if (checkBox2.isChecked() &&
- checkBox3.isChecked() &&
- !checkBox1.isChecked()) {
- // do something
- Score++;
- }else {
- Score--;
- }
- }
- public void Q4AnswerField(View view) {
- EditText editText = (EditText) findViewById(R.id.Q4Answer);
- String userString = editText.getText().toString();
- String answer = "Egypt";
- boolean isAnswerTrue = "Egypt".equalsIgnoreCase("egypt");
- if (isAnswerTrue) {
- Score++;
- }else {
- Score--;
- }
- }
- }
Add Comment
Please, Sign In to add comment