You are on page 1of 3

package com.example.vikasojha.

quizbee;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class QuestionsActivity extends AppCompatActivity {


TextView tv;
Button submitbutton, quitbutton;
RadioGroup radio_g;
RadioButton rb1,rb2,rb3,rb4;

String questions[] = {
"The assassination of the Archduke was followed by ____
throughout the whole European continent.",
"He was treated like a __ and cast out from his
community.",
"There was a major accident. The plane crashed. The
pilot ___ did not see the tower.",
"Non-violence is the law of saints as violence is the
law of the ___",
"I never miss a cricket match. I ___ fond of cricket
since childhood.",
"We felt as if the ground were __ beneath our feet.",
"The task seemed impossible but somehow he ___ very
skillfully in the end.",
"I decided to sell a piece of land when I was offered a
more ___ price.",
"If a man keeps his fingers crossed, he ___",
"His moral decadence was marked by his ___ from the
ways of integrity and honesty."
};
String answers[] = {"repercussions","pariah","probably","brute","have
been","slipping","pulled it out"," realistic","Hopes for the best","Departure"};
String opt[] = {
"consternations","reprisals","concatenations","repercussions",
"pariah"," prodigal","prodigy"," ascetic",
"hurriedly","scarcely","probably"," likely",
" ignorant"," haughty","coward","brute",
"am"," will be","has been"," have been",
"smashing","slipping","sinking","bursting",
"pulled it up","pulled it out","pulled it away","pulled it
off",
" realistic","true","correct","exact",
"Prays for good health","Demonstrates peevishness","Suspects
everybody","Hopes for the best",
"Departure","opprobrium","obsession","declivity"
};
int flag=0;
public static int marks=0,correct=0,wrong=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_questions);

final TextView score = (TextView)findViewById(R.id.textView4);


TextView textView=(TextView)findViewById(R.id.DispName);
Intent intent = getIntent();
String name= intent.getStringExtra("myname");

if (name.trim().equals(""))
textView.setText("Hello User");
else
textView.setText("Hello " + name);

submitbutton=(Button)findViewById(R.id.button3);
quitbutton=(Button)findViewById(R.id.buttonquit);
tv=(TextView) findViewById(R.id.tvque);

radio_g=(RadioGroup)findViewById(R.id.answersgrp);
rb1=(RadioButton)findViewById(R.id.radioButton);
rb2=(RadioButton)findViewById(R.id.radioButton2);
rb3=(RadioButton)findViewById(R.id.radioButton3);
rb4=(RadioButton)findViewById(R.id.radioButton4);
tv.setText(questions[flag]);
rb1.setText(opt[0]);
rb2.setText(opt[1]);
rb3.setText(opt[2]);
rb4.setText(opt[3]);
submitbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//int color = mBackgroundColor.getColor();
//mLayout.setBackgroundColor(color);

if(radio_g.getCheckedRadioButtonId()==-1)
{
Toast.makeText(getApplicationContext(), "Please select one
choice", Toast.LENGTH_SHORT).show();
return;
}
RadioButton uans = (RadioButton)
findViewById(radio_g.getCheckedRadioButtonId());
String ansText = uans.getText().toString();
// Toast.makeText(getApplicationContext(), ansText,
Toast.LENGTH_SHORT).show();
if(ansText.equals(answers[flag])) {
correct++;
Toast.makeText(getApplicationContext(), "Correct",
Toast.LENGTH_SHORT).show();
}
else {
wrong++;
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
}

flag++;
if (score != null)
score.setText(""+correct);

if(flag<questions.length)
{
tv.setText(questions[flag]);
rb1.setText(opt[flag*4]);
rb2.setText(opt[flag*4 +1]);
rb3.setText(opt[flag*4 +2]);
rb4.setText(opt[flag*4 +3]);
}
else
{
marks=correct;
Intent in = new
Intent(getApplicationContext(),ResultActivity.class);
startActivity(in);
}
radio_g.clearCheck();
}
});

quitbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new
Intent(getApplicationContext(),ResultActivity.class);
startActivity(intent);
}
});
}

You might also like