Gleis
Lurker
Tried many methods by changing the code, but it closes every time I press the "Try" button. You can find the Design, XML & Java code below. Also Android Studio is up to date.
The "//" is the old code I tried.
The "//" is the old code I tried.
Java:
public class MainActivity extends AppCompatActivity {
//int randomNumber;
public void higher_lower (View view){
EditText var1= (EditText) findViewById(R.id.TextField);
int var = Integer.parseInt(var1.getText().toString());
int randomNumber;
Random var2 = new Random();
randomNumber =var2.nextInt(0-20)+20;
String message;
if(var>randomNumber){
message ="The number is larger";
//Toast.makeText(this, "The hidden number is larger", Toast.LENGTH_SHORT).show();
}else if (var<randomNumber){
message="The number is smaller";
//Toast.makeText(this, "The hidden number is smaller", Toast.LENGTH_SHORT).show();
}else{
message="BINGO!";
//Toast.makeText(this, "BINGO!", Toast.LENGTH_SHORT).show();
}
//Log.i("Info" , var3);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Random var2 = new Random();
//randomNumber = var2.nextInt(0-20)+20;
}