Created
April 11, 2017 17:33
-
-
Save mmarquezs/c934bc74ab8ab827e62380942bf4886d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <ScrollView | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content"> | |
| <LinearLayout | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context="com.example.android.quizapp.MainActivity" | |
| android:orientation="vertical" | |
| android:padding="20dp"> | |
| <LinearLayout | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:orientation="vertical" | |
| android:paddingBottom="10dp"> | |
| <TextView | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="Check the true statements:"/> | |
| <CheckBox | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="This app is for an iOS device" | |
| android:id="@+id/checkboxTrueFalseQuestion1"/> | |
| <CheckBox | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="This project is for beginners" | |
| android:id="@+id/checkboxTrueFalseQuestion2"/> | |
| <CheckBox | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="<- This is a checkbox" | |
| android:id="@+id/checkboxTrueFalseQuestion3"/> | |
| </LinearLayout> | |
| <LinearLayout | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:orientation="vertical" | |
| android:paddingBottom="10dp"> | |
| <TextView | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="What is the first name of the president of the United States of America?"/> | |
| <EditText | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/text_question_name_president" | |
| android:hint="Insert name here"/> | |
| </LinearLayout> | |
| <LinearLayout | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:orientation="vertical" | |
| android:paddingBottom="10dp"> | |
| <TextView | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="What is the name of this course?"/> | |
| <RadioGroup | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radiogroup_name_course"> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton1_name_course" | |
| android:text="iOS for Beginners"/> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton2_name_course" | |
| android:text="Android Development for Beginners"/> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton3_name_course" | |
| android:text="Android Development for Experts"/> | |
| </RadioGroup> | |
| </LinearLayout> | |
| <LinearLayout | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:orientation="vertical" | |
| android:paddingBottom="10dp"> | |
| <TextView | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="What website is this course from?"/> | |
| <RadioGroup | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioGroup_website_course"> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton1_website_course" | |
| android:text="https://www.udacity.com"/> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton2_website_course" | |
| android:text="https://www.google.com"/> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton3_website_course" | |
| android:text="https://androidfor.beginners.com"/> | |
| </RadioGroup> | |
| </LinearLayout> | |
| <LinearLayout | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:orientation="vertical" | |
| android:paddingBottom="10dp"> | |
| <TextView | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="How many lessons has this course?"/> | |
| <RadioGroup | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioGroup_number_lessons" | |
| android:orientation="horizontal"> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton1_number_lessons" | |
| android:text="1"/> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton2_number_lessons" | |
| android:text="2"/> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton3_number_lessons" | |
| android:text="3"/> | |
| <RadioButton | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:id="@+id/radioButton4_number_lessons" | |
| android:text="4"/> | |
| </RadioGroup> | |
| </LinearLayout> | |
| <Button | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content" | |
| android:onClick="verify" | |
| android:text="verify answers"/> | |
| </LinearLayout> | |
| </ScrollView> |
This file contains hidden or 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
| package com.example.android.quizapp; | |
| import android.os.Bundle; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.view.View; | |
| import android.widget.CheckBox; | |
| import android.widget.EditText; | |
| import android.widget.RadioGroup; | |
| import android.widget.Toast; | |
| public class MainActivity extends AppCompatActivity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| } | |
| public void verify(View v) { | |
| int correctAnswers = 0; | |
| CheckBox check1 = (CheckBox) findViewById(R.id.checkboxTrueFalseQuestion1); | |
| CheckBox check2 = (CheckBox) findViewById(R.id.checkboxTrueFalseQuestion2); | |
| CheckBox check3 = (CheckBox) findViewById(R.id.checkboxTrueFalseQuestion3); | |
| if (!check1.isChecked()) { | |
| correctAnswers+=1; | |
| } | |
| if (check2.isChecked()) { | |
| correctAnswers+=1; | |
| } | |
| if (check3.isChecked()) { | |
| correctAnswers+=1; | |
| } | |
| EditText editText = (EditText) findViewById(R.id.text_question_name_president); | |
| if (editText.getText().toString().equalsIgnoreCase("donald")) { | |
| correctAnswers+=1; | |
| } | |
| RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radiogroup_name_course); | |
| if (radioGroup.getCheckedRadioButtonId() == R.id.radioButton2_name_course) { | |
| correctAnswers+=1; | |
| } | |
| RadioGroup radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup_website_course); | |
| if (radioGroup2.getCheckedRadioButtonId() == R.id.radioButton1_website_course) { | |
| correctAnswers+=1; | |
| } | |
| RadioGroup radioGroup3 = (RadioGroup) findViewById(R.id.radioGroup_number_lessons); | |
| if (radioGroup3.getCheckedRadioButtonId() == R.id.radioButton3_number_lessons) { | |
| correctAnswers+=1; | |
| } | |
| Toast.makeText(getApplicationContext(),"Result: "+String.valueOf(correctAnswers)+" correct answers out of 7.",Toast.LENGTH_LONG).show(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment