2017-07-08 7 views
-2

私はクイズアプリを作成しています。貼り付けられたコードはアプリの2番目のアクティビティです。しかし、それはint point = 0と述べており、最終点はクイズの答えに依存するので記述されていません。 しかし、私はこのアクティビティの中のどんな答えも、次のものと次のものに渡します。ここAndroidのアクティビティ間で整数を渡す

はactivity2のコードです:あなたの意図を起動する前に

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(); 
     } 
} 
} 

答えて

0

、エキストラを渡します。この質問は、重複していると、すでに詳細な解が存在する:

yourIntent.putExtra("points", finalpoints); 

を、それまでの変数あなたのfinalpointsを配置し、次の活動でそれを取得する:あなたは次のアクティビティへの意思を作成するときHow do I pass data between Activities in Android application?

+2

質問は本当に重複しているので、投稿しないでください - 単にコメントを書くか、恐らくそれを重複としてフラグを立ててください:) – 0X0nosugar

関連する問題