开发者

onClick function not working

开发者 https://www.devze.com 2023-03-14 05:36 出处:网络
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 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(); }

0

精彩评论

暂无评论...
验证码 换一张
取 消