我试图用“ int”值制作一个非常简单的计算器。问题是:无论计算出多少数字,答案都是“ 0”。我的代码有什么问题,我该如何解决? (例如,这是我的代码,还有其他内容)
private EditText input;
private EditText input2;
private TextView result;
private Button plus;
private String inputStr;
private String input2Str;
private int inp1;
private int inp2;
private int rslt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input = findViewById(R.id.input);
input2 = findViewById(R.id.input2);
result = findViewById(R.id.result);
plus = findViewById(R.id.plus_btn);
input.setOnClickListener(v -> {
inputStr = input.getText().toString();
inp1 = Integer.parseInt(inputStr);
});
input2.setOnClickListener(v -> {
input2Str = input2.getText().toString();
inp2 = Integer.parseInt(input2Str);
});
rslt = 0;
plus.setOnClickListener(v -> {
rslt = inp1 + inp2;
result.setText(String.valueOf(rslt));
});
答案 0 :(得分:0)
const { players } = this.state
const { card } = this.props.classes
return (
<div className="GameConfig">
<h1>Salon de jeu</h1>
<div className="well" style={this.wellStyles}>
<h2>Informations</h2>
Id : {this.gameId}
<br></br>
<h2>Players (0/2)</h2>
<div id="cards">
</div>
{players.map(player =>
<Card className={card} key={player}>
<CardHeader
avatar={
<Avatar style={{ backgroundColor: "#00FF00" }} aria-label="Recipe">
R
</Avatar>
}
action={
<IconButton>
<MoreVertIcon />
</IconButton>
}
title={player}
subheader=""
/>
</Card>
)}
<form onSubmit={this.handleFormSubmit}>
<br></br>
<Button bsStyle="primary" type="submit" bsSize="large" block>
Lancer la partie
</Button>
</form>
</div>
<ToastContainer store={ToastStore} />
</div>
)