Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dithero.test;
- /**
- * Created by Kaye on 3/10/2015.
- */
- import android.content.DialogInterface;
- import android.support.v7.app.ActionBarActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.content.Intent;
- import android.widget.Button;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- public class G1 extends ActionBarActivity implements View.OnClickListener{
- //declare everything to be used
- String[] q, A, B, C, D, correct;// rat,id;
- TextView tq, tr;
- Button back, next, show;
- RadioButton a, b, c, d;
- int index, score, total;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //initialize our number counters yaaay! CORRECT
- index = 0;
- score = 0;
- total = 0;
- //initializing texts of questions and rationale CORRECT
- tq = (TextView) findViewById(R.id.question);
- //initialize string arrays of everything CORRRECT
- q = getResources().getStringArray(R.array.G1q);
- A = getResources().getStringArray(R.array.G1A);
- B = getResources().getStringArray(R.array.G1B);
- C = getResources().getStringArray(R.array.G1C);
- D = getResources().getStringArray(R.array.G1D);
- correct = getResources().getStringArray(R.array.G1correct);
- //initialize movin' on buttons from layout CORRECT
- back = (Button) findViewById(R.id.back);
- next = (Button) findViewById(R.id.next);
- show = (Button) findViewById(R.id.show);
- //initialize the radio buttons!!!!!!!!! HOMG IT WORKS
- RadioGroup rg=(RadioGroup) findViewById(R.id.choice);
- a=(RadioButton) findViewById(R.id.a);
- b=(RadioButton) findViewById(R.id.b);
- c=(RadioButton) findViewById(R.id.c);
- d=(RadioButton) findViewById(R.id.d);
- // brings to life the strings. heavenly strings! CORRECT
- a.setText(A[index]);
- b.setText(B[index]);
- c.setText(C[index]);
- d.setText(D[index]);
- //putting the text from strings in text boxes CORRRECT NA
- tq.setText(q[index]);
- tr.setText("Read carefully");
- //implement clicking. fuuuuuuuu.what is this DONT FORGET TO CORRECT THIS
- back.setOnClickListener(this);
- next.setOnClickListener(this);
- show.setOnClickListener(this);
- //TIME to get the answer from the radio group
- }
- //@Override
- public void onClick(View v) {
- switch (v.getId()) {
- //for the back button so minus answer and rationale hide
- case R.id.back:
- tr.setText("read carefully"); //hides the rationale
- index--;
- if(index==-1) { //to start a loop so the app doesnt crash
- index=q.length-1;
- tq.setText(q[index]);
- a.setText(A[index]);
- b.setText(B[index]);
- c.setText(C[index]);
- d.setText(D[index]);
- }
- else {
- //just normal things, going back to the last question
- tq.setText(q[index]);
- a.setText(A[index]);
- b.setText(B[index]);
- c.setText(C[index]);
- d.setText(D[index]);
- }
- break;
- //for the next button so plus question and choices and hide rationale
- case R.id.next:
- tr.setText("Read carefully");
- index++;
- if(index==q.length){
- index=0;
- tq.setText(q[index]);
- a.setText(A[index]);
- b.setText(B[index]);
- c.setText(C[index]);
- d.setText(D[index]);
- }
- else{
- tq.setText(q[index]);
- a.setText(A[index]);
- b.setText(B[index]);
- c.setText(C[index]);
- d.setText(D[index]); }
- break;
- //for showing the answer, so just rationale. add checked radio button
- case R.id.show:
- //compare answer and correct one, add scores
- RadioGroup choice = (RadioGroup) findViewById(R.id.choice); //finds the radio group
- int selectedId = choice.getCheckedRadioButtonId(); //finds the checked ID
- RadioButton nerf=(RadioButton) findViewById(selectedId); //gets checked button,
- String id= nerf.getText().toString(); //then convert to string
- // tr.setText(String.valueof(id)+rat[index]);
- if(id.equals(correct[index]))
- {
- total++;
- score++;
- tr.setText("Correct!"+"/n"+correct[index]+"/n"+"Score:"+score+"/"+total); //shows the rationale CORRRRRECT with score
- }
- else{
- total++;
- tr.setText("Sorry, not that one"+"/n"+correct[index]+"/n"+"Score:"+score+"/"+total); //shows the rationale and if wrong
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement