Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. package dithero.test;
  2.  
  3. /**
  4. * Created by Kaye on 3/10/2015.
  5. */
  6.  
  7. import android.content.DialogInterface;
  8. import android.support.v7.app.ActionBarActivity;
  9. import android.os.Bundle;
  10. import android.view.Menu;
  11. import android.view.MenuItem;
  12. import android.view.View;
  13. import android.content.Intent;
  14. import android.widget.Button;
  15. import android.widget.RadioButton;
  16. import android.widget.RadioGroup;
  17. import android.widget.TextView;
  18.  
  19. public class G1 extends ActionBarActivity implements View.OnClickListener{
  20. //declare everything to be used
  21. String[] q, A, B, C, D, correct;// rat,id;
  22. TextView tq, tr;
  23. Button back, next, show;
  24. RadioButton a, b, c, d;
  25. int index, score, total;
  26.  
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.activity_main);
  31. //initialize our number counters yaaay! CORRECT
  32. index = 0;
  33. score = 0;
  34. total = 0;
  35.  
  36. //initializing texts of questions and rationale CORRECT
  37. tq = (TextView) findViewById(R.id.question);
  38.  
  39.  
  40. //initialize string arrays of everything CORRRECT
  41. q = getResources().getStringArray(R.array.G1q);
  42. A = getResources().getStringArray(R.array.G1A);
  43. B = getResources().getStringArray(R.array.G1B);
  44. C = getResources().getStringArray(R.array.G1C);
  45. D = getResources().getStringArray(R.array.G1D);
  46. correct = getResources().getStringArray(R.array.G1correct);
  47.  
  48.  
  49. //initialize movin' on buttons from layout CORRECT
  50. back = (Button) findViewById(R.id.back);
  51. next = (Button) findViewById(R.id.next);
  52. show = (Button) findViewById(R.id.show);
  53.  
  54. //initialize the radio buttons!!!!!!!!! HOMG IT WORKS
  55. RadioGroup rg=(RadioGroup) findViewById(R.id.choice);
  56. a=(RadioButton) findViewById(R.id.a);
  57. b=(RadioButton) findViewById(R.id.b);
  58. c=(RadioButton) findViewById(R.id.c);
  59. d=(RadioButton) findViewById(R.id.d);
  60.  
  61. // brings to life the strings. heavenly strings! CORRECT
  62. a.setText(A[index]);
  63. b.setText(B[index]);
  64. c.setText(C[index]);
  65. d.setText(D[index]);
  66.  
  67.  
  68.  
  69. //putting the text from strings in text boxes CORRRECT NA
  70. tq.setText(q[index]);
  71. tr.setText("Read carefully");
  72.  
  73. //implement clicking. fuuuuuuuu.what is this DONT FORGET TO CORRECT THIS
  74. back.setOnClickListener(this);
  75. next.setOnClickListener(this);
  76. show.setOnClickListener(this);
  77.  
  78.  
  79. //TIME to get the answer from the radio group
  80. }
  81.  
  82. //@Override
  83. public void onClick(View v) {
  84. switch (v.getId()) {
  85. //for the back button so minus answer and rationale hide
  86. case R.id.back:
  87. tr.setText("read carefully"); //hides the rationale
  88. index--;
  89. if(index==-1) { //to start a loop so the app doesnt crash
  90. index=q.length-1;
  91. tq.setText(q[index]);
  92. a.setText(A[index]);
  93. b.setText(B[index]);
  94. c.setText(C[index]);
  95. d.setText(D[index]);
  96. }
  97. else {
  98. //just normal things, going back to the last question
  99. tq.setText(q[index]);
  100. a.setText(A[index]);
  101. b.setText(B[index]);
  102. c.setText(C[index]);
  103. d.setText(D[index]);
  104.  
  105. }
  106. break;
  107.  
  108. //for the next button so plus question and choices and hide rationale
  109. case R.id.next:
  110. tr.setText("Read carefully");
  111. index++;
  112. if(index==q.length){
  113. index=0;
  114. tq.setText(q[index]);
  115. a.setText(A[index]);
  116. b.setText(B[index]);
  117. c.setText(C[index]);
  118. d.setText(D[index]);
  119. }
  120. else{
  121. tq.setText(q[index]);
  122. a.setText(A[index]);
  123. b.setText(B[index]);
  124. c.setText(C[index]);
  125. d.setText(D[index]); }
  126. break;
  127.  
  128. //for showing the answer, so just rationale. add checked radio button
  129. case R.id.show:
  130.  
  131. //compare answer and correct one, add scores
  132.  
  133.  
  134. RadioGroup choice = (RadioGroup) findViewById(R.id.choice); //finds the radio group
  135. int selectedId = choice.getCheckedRadioButtonId(); //finds the checked ID
  136. RadioButton nerf=(RadioButton) findViewById(selectedId); //gets checked button,
  137. String id= nerf.getText().toString(); //then convert to string
  138. // tr.setText(String.valueof(id)+rat[index]);
  139. if(id.equals(correct[index]))
  140. {
  141. total++;
  142. score++;
  143. tr.setText("Correct!"+"/n"+correct[index]+"/n"+"Score:"+score+"/"+total); //shows the rationale CORRRRRECT with score
  144.  
  145. }
  146. else{
  147. total++;
  148. tr.setText("Sorry, not that one"+"/n"+correct[index]+"/n"+"Score:"+score+"/"+total); //shows the rationale and if wrong
  149.  
  150. }
  151. break;
  152. }
  153. }
  154.  
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement