I have two Editext
and need them both to be true to access the second page, but even if both are false when you click on the button it accesses the second page regardless.
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 } }
Advertisement
Answer
Use && not &. && is a logical AND, & is bitwise.