Skip to content

Instantly share code, notes, and snippets.

@desinas
Last active May 29, 2017 19:02
Show Gist options
  • Save desinas/37dd3577c2112f0ebd8172da53452ba3 to your computer and use it in GitHub Desktop.
Save desinas/37dd3577c2112f0ebd8172da53452ba3 to your computer and use it in GitHub Desktop.
The QUIZ GAME project for education of Android framework.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.disinas.quiz.MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question1"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/question1">
<RadioButton
android:id="@+id/correct_answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/answer1"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/answer1"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/answer1"/>
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/score_button"
android:onClick="score_button"/>
<TextView
android:id="@+id/score_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
/>
</LinearLayout>
package com.example.disinas.quiz;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.view.View;
public class MainActivity extends AppCompatActivity {
int score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private void checkQuestion1(){
RadioGroup questionRadioGroup = (RadioGroup) findViewById(R.id.question1);
if (questionRadioGroup.getCheckedRadioButtonId() == R.id.correct_answer)
score++;
}
private void displayScore( int score){
TextView scoreTextView = (TextView) findViewById(R.id.score_text_view);
String message = "Score: " + score;
scoreTextView.setText(message);
}
public void score_button(View view){
score = 0;
checkQuestion1();
displayScore(score);
}
}
<resources>
<string name="app_name">Quiz</string>
<string name="question1">WHAT.....?</string>
<string name="answer1">This is fdsfdfd fds fds fdsf dsff</string>
<string name="score_button">Submit answers</string>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment