IF语句未按预期工作.无法让AND工作



我有两个Editext,需要它们都为true才能访问第二个页面,但即使当您单击按钮时两者都为false,它也会访问第二页。

public void DoSubmit(View view) {
String guessSize = weight.getText().toString();
String guessSize2 = height.getText().toString();
if ((Integer.parseInt(guessSize) <= 20 || Integer.parseInt(guessSize) >= 200) & (Integer.parseInt(guessSize2) <= 80 || Integer.parseInt(guessSize2) >= 300) ) {
Toast.makeText(MainActivity.this, "Enter value between 20kg and 200kg", Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "Enter value between 20kg and 200kg", Toast.LENGTH_SHORT).show();
}
else {
Intent summaryActivity = new Intent(view.getContext(), secondpage.class);
int weightkg = Integer.valueOf(weight.getText().toString());
int heightcm = Integer.valueOf(height.getText().toString());
summaryActivity.putExtra("weight", weightkg);
summaryActivity.putExtra("height", heightcm);
startActivity(summaryActivity);     // start the new page
}

}

使用&amp;不是&amp;是逻辑AND,&是逐位的。

相关内容

  • 没有找到相关文章

最新更新