我有一个问题,分数没有递增,我在做自己的测验时得到的信息是,当我点击了所有正确的答案时,我得到了3分。有人可以快点看看我做错了什么吗?提前谢谢!
public class MainActivity extends AppCompatActivity {
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
score = 0;
final CheckedTextView check1 = (CheckedTextView) findViewById(R.id.Q1answerA);
check1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
score++;
check1.toggle();
newActivity1();
}
});
final CheckedTextView check2 = (CheckedTextView) findViewById(R.id.Q1answerB);
check2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check2.toggle();
newActivity1();
}
});
final CheckedTextView check3 = (CheckedTextView) findViewById(R.id.Q1answerC);
check3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check3.toggle();
newActivity1();
}
});
}
public void newActivity1() {
Intent intent = new Intent(MainActivity.this, NewActivity1.class);
startActivity(intent);
}
public int getScore1(){
return this.score;
}
}
newActivity
public class NewActivity1 extends AppCompatActivity {
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new1);
score = 0;
final CheckedTextView check1 = (CheckedTextView) findViewById(R.id.Q2answerA);
check1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check1.toggle();
newActivity2();
}
});
final CheckedTextView check2 = (CheckedTextView) findViewById(R.id.Q2answerB);
check2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
score++;
check2.toggle();
newActivity2();
}
});
final CheckedTextView check3 = (CheckedTextView) findViewById(R.id.Q2answerC);
check3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check3.toggle();
newActivity2();
}
});
}
public void newActivity2() {
Intent intent = new Intent(NewActivity1.this, NewActivity2.class);
startActivity(intent);
}
public int getScore2() {
return this.score;
}
}
newActivity
public class NewActivity2 extends AppCompatActivity {
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new2);
score = 0;
final CheckedTextView check1 = (CheckedTextView) findViewById(R.id.Q3answerA);
check1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
score++;
check1.toggle();
newActivity3();
}
});
final CheckedTextView check2 = (CheckedTextView) findViewById(R.id.Q3answerB);
check2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check2.toggle();
newActivity3();
}
});
final CheckedTextView check3 = (CheckedTextView) findViewById(R.id.Q3answerC);
check3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
check3.toggle();
newActivity3();
}
});
}
public void newActivity3() {
Intent intent = new Intent(NewActivity2.this, NewActivity3.class);
startActivity(intent);
}
public int getScore3() {
return this.score;
}
}
newActivity
public class NewActivity3 extends AppCompatActivity {
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new3);
score = 0;
score();
textScore();
}
public void score() {
MainActivity main = new MainActivity();
NewActivity1 ac1 = new NewActivity1();
NewActivity2 ac2 = new NewActivity2();
if (main.getScore1() == 1) {
score++;
}
if (ac1.getScore2() == 1) {
score++;
}
if (ac2.getScore3() == 1) {
score++;
}
}
public int getScore() {
return this.score;
}
public void textScore() {
if (getScore() == 3) {
TextView score3 = (TextView) findViewById(R.id.score3);
score3.setVisibility(View.VISIBLE);
} else if (getScore() == 2) {
TextView score2 = (TextView) findViewById(R.id.score2);
score2.setVisibility(View.VISIBLE);
} else if (getScore() == 1) {
TextView score1 = (TextView) findViewById(R.id.score1);
score1.setVisibility(View.VISIBLE);
} else if (getScore() == 0) {
TextView score0 = (TextView) findViewById(R.id.score0);
score0.setVisibility(View.VISIBLE);
}
}
}