Reputation:
I want to create simple app which will display Toast message,using my own function called Count_BMI (later to develop)
Button submit ;
EditText weight;
EditText height;
EditText BMI;
int BMI_value;
String text = "Hello Adam";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button submit = findViewById(R.id.btnSumit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Count_BMI();
}
});
}
public void Count_BMI() {
}
Toast.makeText(getApplicationContext(),
"This a toast message",
Toast.LENGTH_LONG)
.show();
}
Why I cant display Toast in my own function? This is the error:
Upvotes: 0
Views: 153
Reputation: 75
Need change:
public void Count_BMI() {
}
Toast.makeText(getApplicationContext(), "This a toast message", Toast.LENGTH_LONG) .show();
To:
public void Count_BMI() {
Toast.makeText(getApplicationContext(), "This a toast message", Toast.LENGTH_LONG) .show();
}
The problem is that you wrote the toast outside the brackets
Upvotes: 0
Reputation: 318
The toast is outside the void, it should be:
public void Count_BMI() {
Toast.makeText(getApplicationContext(),"This a toast message",Toast.LENGTH_LONG).show();
}
Upvotes: 1