onClick function not working
I am having problems with a button, I'm trying to set it on SetOnClickListener function, and tells it what to do when onClick, but it's giving me error messages that I can't figure out why.
I keep on getting these error messages: Multiple markers at this line - Syntax error, insert ";" to complete Statement - Syntax error, insert "}" to complete MethodBody - Syntax error, insert ")" to complete
Here's the code:
calculate.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(this, "The Amount a Person has to pay: $" + result, Toast.LEN开发者_如何学GoGTH_LONG).show();
}
});
Thank you for all of your kind feedbacks
Your code looks fine. You have a syntax error further up.
import android.view.View.OnClickListener;
change this line Toast.makeText(this, "The Amount a Person has to pay: $" + result, Toast.LENGTH_LONG).show(); }
to
Toast.makeText(v.getContext(), "The Amount a Person has to pay: $" + result, Toast.LENGTH_LONG).show(); }
精彩评论