Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- int defaultScore = 51;
- // start Play Intent
- public void onPlay(View view){
- Random r = new Random();
- int XML_random = r.nextInt(5)+1; // 5 different Quiz XML files
- Intent startQuiz = new Intent();
- switch(XML_random){
- case 1:
- startQuiz.setClass(view.getContext(), Quiz_1.class);
- break;
- case 2:
- startQuiz.setClass(view.getContext(), Quiz_2.class);
- break;
- case 3:
- startQuiz.setClass(view.getContext(), Quiz_3.class);
- break;
- case 4:
- startQuiz.setClass(view.getContext(), Quiz_4.class);
- break;
- case 5:
- startQuiz.setClass(view.getContext(), Quiz_5.class);
- break;
- } // end of the Random switch
- startQuiz.putExtra("passScore", defaultScore);
- startActivity(startQuiz);
- }
- 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.
- Question 1 - user clicks on the wrong button:
- public class Quiz_1 extends Activity {
- TextView textviewScore;
- int current_score = 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.quiz_1);
- textviewScore = (TextView) findViewById(R.id.q_result); // declaring the TextView
- Bundle extras = getIntent().getExtras();
- if (extras != null)
- {
- current_score = extras.getInt("passScore");
- }
- textviewScore.setText(String.valueOf(current_score));
- } // end of onCreate
- public void on_quiz_1_wrong(View view){ // button clicked the wrong answer
- current_score = current_score - 2;
- Intent quiz1 = new Intent(this, Quiz_2.class);
- startActivity(quiz1);
- quiz1.putExtra("passNewScore", current_score);
- }
- And here is Question #2, and for this activity i want the score to be minus 2.
- public class Quiz_2 extends Activity {
- TextView textviewScore;
- int current_score = 0;
- int getScore=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.quiz_2);
- textviewScore = (TextView) findViewById(R.id.q_result); // declaring the TextView
- Bundle extras = getIntent().getExtras();
- if (extras != null)
- {
- current_score = extras.getInt("passScore");
- getScore = extras.getInt("passNewScore");
- }
- current_score = current_score - getScore;
- textviewScore.setText(String.valueOf(current_score));
- } // end of onCreate
- I hope, it's now understantable, please help!!! then, i will accept your answer
Advertisement
Add Comment
Please, Sign In to add comment