Guest User

...

a guest
Nov 3rd, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.99 KB | None | 0 0
  1. EDIT: So, here is the code from the main activity(the main screen,) if you click on play a random activity( a quiz question) will show up.
  2.  
  3.  int defaultScore = 51;
  4.  
  5.  
  6.  
  7. // start Play Intent
  8. public void onPlay(View view){
  9.     Random r = new Random();
  10.     int XML_random = r.nextInt(5)+1; // 5 different Quiz XML files
  11.     Intent startQuiz = new Intent();
  12.     switch(XML_random){
  13.     case 1:
  14.         startQuiz.setClass(view.getContext(), Quiz_1.class);
  15.     break;
  16.     case 2:
  17.         startQuiz.setClass(view.getContext(), Quiz_2.class);
  18.     break;
  19.     case 3:
  20.         startQuiz.setClass(view.getContext(), Quiz_3.class);
  21.     break;
  22.     case 4:
  23.         startQuiz.setClass(view.getContext(), Quiz_4.class);
  24.     break;
  25.     case 5:
  26.         startQuiz.setClass(view.getContext(), Quiz_5.class);
  27.     break;
  28.     } // end of the Random switch
  29.     startQuiz.putExtra("passScore", defaultScore);
  30.     startActivity(startQuiz);
  31.  
  32. }
  33. So, next if a random activity is chosen, then it's score will be 5, because for the first question, I want the users to start with 5 as a start. So, here is an activty(Question #1) and if the user clicks on the wrong button then Question #2 will show up. And for this activity, the score will be minus 2. Because the user chose the wrong answer.
  34.  
  35. Question 1 - user clicks on the wrong button:
  36.  
  37. public class Quiz_1 extends Activity {
  38. TextView textviewScore;
  39. int current_score = 0;
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43.    // TODO Auto-generated method stub
  44.    super.onCreate(savedInstanceState);
  45.    setContentView(R.layout.quiz_1);
  46.    textviewScore = (TextView) findViewById(R.id.q_result);   // declaring the TextView
  47.    Bundle extras = getIntent().getExtras();
  48.    if (extras != null)
  49.     {
  50.       current_score   = extras.getInt("passScore");
  51.    }
  52.  
  53.    textviewScore.setText(String.valueOf(current_score));
  54.  
  55. } // end of onCreate
  56.  
  57. public void on_quiz_1_wrong(View view){  // button clicked the wrong answer
  58.    current_score = current_score - 2;
  59.    Intent quiz1 = new Intent(this, Quiz_2.class);
  60.    startActivity(quiz1);
  61.    quiz1.putExtra("passNewScore", current_score);
  62.  
  63. }
  64. And here is Question #2, and for this activity i want the score to be minus 2.
  65.  
  66. public class Quiz_2 extends Activity {
  67. TextView textviewScore;
  68. int current_score = 0;
  69. int getScore=0;
  70. @Override
  71. protected void onCreate(Bundle savedInstanceState) {
  72.    // TODO Auto-generated method stub
  73.    super.onCreate(savedInstanceState);
  74.    setContentView(R.layout.quiz_2);
  75.    textviewScore = (TextView) findViewById(R.id.q_result);   // declaring the TextView
  76.    Bundle extras = getIntent().getExtras();
  77.    if (extras != null)
  78.     {
  79.       current_score   = extras.getInt("passScore");
  80.       getScore = extras.getInt("passNewScore");
  81.    }
  82.    current_score = current_score - getScore;
  83.    textviewScore.setText(String.valueOf(current_score));
  84.  
  85. } // end of onCreate
  86. I hope, it's now understantable, please help!!! then, i will accept your answer
Advertisement
Add Comment
Please, Sign In to add comment