当我单击一个按钮时,我需要该按钮仅传递选定的字符串。
如果 Integer 为 2,我会尝试传递一个特定的字符串。
显示这是我的第一个名为 PlayerChoose 的活动:
//PI1 and PI2 is Strings from another Activity.
PI1 = getIntent().getStringExtra("Player1Text");
PI2 = getIntent().getStringExtra("Player2Text");
//These bellow are buttons.
Player1Btn = findViewById(R.id.PlayerToD1);
Player2Btn = findViewById(R.id.PlayerToD2);
//These Integers is to set 0 so the app is not broken.
PlayerInt1 = 0;
PlayerInt2 = 0;
//Here im setting text to the buttons so you know what player you pick
Player1Btn.setText(PI1);
Player2Btn.setText(PI2);
//These button adds 1 to the Integer PlayerInt1 so if you hit it
//twice it executes what is in the if statement.
Player1Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlayerInt1++;
if (PlayerInt1 == 2) {
Intent TruthOrDare1 = new Intent(PlayerChoose.this,TruthOrDare.class);
TruthOrDare1.putExtras(getIntent());
TruthOrDare1.putExtra("Player1Text", PI1);
startActivity(TruthOrDare1);
}
}
});
//Same button as Player1Btn Does the same things.
Player2Btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlayerInt2++;
if (PlayerInt2 == 2) {
Intent TruthOrDare2 = new Intent(PlayerChoose.this,TruthOrDare.class);
TruthOrDare2.putExtras(getIntent());
TruthOrDare2.putExtra("Player2Text", PI2);
startActivity(TruthOrDare2);
}
}
});
}
}
我的问题是,只有当我在 PlayerChoose Activity 中点击 Player1Btn 和 PI2 如果我点击 Player2Btn 时,它才会传递两个字符串 PI1,PI2 而不是 PI1。如果我点击 Player1Btn 和 PI2 如果我点击 PI2,我怎么能只传递 PI1。
紫衣仙女
慕妹3242003
相关分类