2 回答
TA贡献1839条经验 获得超15个赞
看来你有不必要的字符串
TruthOrDare1.putExtras(getIntent()); TruthOrDare2.putExtras(getIntent());
在点击侦听器中,它同时添加了 PI1 和 PI2
TA贡献1824条经验 获得超6个赞
因此,在名为 PlayerChoose 的第一个活动中很简单,您可以创建另一个字符串,无论我将其命名为 PIP1 的示例,这就是您必须做的:
//So Put PI1 as default string of PIP1.
PIP1 = PI1;
//Then in the Buttons OnClickListeners
Player1Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlayerInt1++;
//If you click this button it will set PIP1 to the string you want to
//pass in this case PI1
PIP1 = PI1;
if (PlayerInt1 == 2) {
Intent TruthOrDare1 = new Intent(PlayerChoose.this, TruthOrDare.class);
TruthOrDare1.putExtras(getIntent());
//Intead of putting the text itself you put PIP1 thats changing
//depens on what button you click
TruthOrDare1.putExtra("PlayerText", PIP1);
startActivity(TruthOrDare1);
}
}
});
Player2Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlayerInt2++;
//And here you Change the same string PIP1 to PI2
//Here you change the PIP1 to PI2 so PIP1 change to PI2 and not PI1
PIP1 = PI2;
if (PlayerInt2 == 2) {
Intent TruthOrDare2 = new Intent(PlayerChoose.this, TruthOrDare.class);
TruthOrDare2.putExtras(getIntent());
TruthOrDare2.putExtra("PlayerText", PIP1);
startActivity(TruthOrDare2);
}
}
});
在名为 TruthOrDare 的第二个活动中,您可以更改此内容:
//So you only have 1 String Instead of 2 with 1 key
PI1 = getIntent().getStringExtra("PlayerText");
//One TextView
PlayerTurnName1 = findViewById(R.id.PlayerTurnText1);
PlayerTurnName1.setText(PI1);
这个概念是每次你按下按钮时 PIP1 都会改变,所以它不会传递所有的值。
添加回答
举报