我正在創建一個測驗應用程序。粘貼的代碼是應用程序的第二個活動。但它表明int點= 0,並且終點沒有說明,因爲它取決於測驗中的答案。 但是,我是否會將此活動中的任何答案傳遞給下一個和下一個。在Android中傳遞整數活動
這裏的活性2的代碼:
package com.example.android.questionme;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.Toast;
public class Main2Activity extends AppCompatActivity {
Intent intent = getIntent();
int point = 0;
int finalpoints;
RadioButton option1forQ1;
RadioButton option2forQ1;
RadioButton option1forQ2;
RadioButton option2forQ2;
RadioButton option3forQ2;
RadioButton option4forQ2;
RadioButton option1forQ3;
RadioButton option2forQ3;
RadioButton option3forQ3;
RadioButton option1forQ4;
RadioButton option2forQ4;
RadioButton option3forQ4;
RadioButton option4forQ4;
RadioButton option1forQ5;
RadioButton option2forQ5;
RadioButton option3forQ5;
RadioButton option4forQ5;
CheckBox option1forQ6;
CheckBox option2forQ6;
CheckBox option3forQ6;
CheckBox option4forQ6;
RadioButton option1forQ7;
RadioButton option2forQ7;
RadioButton option3forQ7;
RadioButton option4forQ7;
RadioButton option1forQ8;
RadioButton option2forQ8;
RadioButton option3forQ8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
option1forQ1 = (RadioButton) findViewById(R.id.right_answer_for_Q1);
option2forQ1 = (RadioButton) findViewById(R.id.wrong_answer_for_Q1);
option1forQ2 = (RadioButton) findViewById(R.id.question_two_right_answer);
option2forQ2 = (RadioButton) findViewById(R.id.question_two_wrong_answer0);
option3forQ2 = (RadioButton) findViewById(R.id.question_two_wrong_answer1);
option4forQ2 = (RadioButton) findViewById(R.id.question_two_wrong_answer2);
option1forQ3 = (RadioButton) findViewById(R.id.question_three_right_answer);
option2forQ3 = (RadioButton) findViewById(R.id.question_three_wrong_answer0);
option3forQ3 = (RadioButton) findViewById(R.id.question_three_wrong_answer1);
option1forQ4 = (RadioButton) findViewById(R.id.question_four_wrong_answer0);
option2forQ4 = (RadioButton) findViewById(R.id.question_four_right_answer);
option3forQ4 = (RadioButton) findViewById(R.id.question_four_wrong_answer1);
option4forQ4 = (RadioButton) findViewById(R.id.question_four_wrong_answer2);
option1forQ5 = (RadioButton) findViewById(R.id.question_five_wrong_answer0);
option2forQ5 = (RadioButton) findViewById(R.id.question_five_wrong_answer1);
option3forQ5 = (RadioButton) findViewById(R.id.question_five_wrong_answer2);
option4forQ5 = (RadioButton) findViewById(R.id.question_five_right_answer);
option1forQ6 = (CheckBox) findViewById(R.id.question_six_right_answer);
option2forQ6 = (CheckBox) findViewById(R.id.question_six_wrong_answer);
option3forQ6 = (CheckBox) findViewById(R.id.question_six_wrong_answer1);
option4forQ6 = (CheckBox) findViewById(R.id.question_six_right_answer1);
option1forQ7 = (RadioButton) findViewById(R.id.question_seven_wrong_answer);
option2forQ7 = (RadioButton) findViewById(R.id.question_seven_wrong_answer1);
option3forQ7 = (RadioButton) findViewById(R.id.question_seven_right_answer);
option4forQ7 = (RadioButton) findViewById(R.id.question_seven_wrong_answer2);
option1forQ8 = (RadioButton) findViewById(R.id.question_eight_wrong_answer);
option2forQ8 = (RadioButton) findViewById(R.id.question_eight_right_answer);
option3forQ8 = (RadioButton) findViewById(R.id.question_eight_wrong_answer2);
}
public void onYesRadioButtonClicked (View view){
Intent intent = new Intent(this, Main3Activity.class);
boolean option1forQ1IsChecked = option1forQ1.isChecked();
boolean option2forQ1IsChecked = option2forQ1.isChecked();
if (option1forQ1IsChecked) {
point *= 2;
startActivity(intent);
Toast.makeText(this, "Good Start"+ "2 Points", Toast.LENGTH_SHORT).show();
}
else
if (option2forQ1IsChecked) {
point -= 1;
}
}
public void onNoRadioButtonClicked (View view){
boolean option2forQ1IsChecked = option2forQ1.isChecked();
if (option2forQ1IsChecked){
Toast.makeText(this, "Wrong Answer, You can Google about Google on Google"
, Toast.LENGTH_SHORT).show();
}
}
}
請不要發表一個答案,因爲問題確實是重複的 - 只需寫一條評論或者將其標記爲重複:) – 0X0nosugar