Error due to invalid combination of Toast and OnClickListener

前端 未结 7 1955
醉梦人生
醉梦人生 2021-01-31 08:54

I\'m trying to use Toast inside OnCLickListener. My code triggers the following error:

The method makeText(Context, CharSequence, int)          


        
7条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 08:58

    As The Kenny said, this is refering to the View.OnClickListener instead of your Activity. Change this, to MyActivity.this.

    For example,

    public class MyActivity extends Activity {
    // ... other code here
    Toast.makeText(MyActivity.this, Lname, Toast.LENGTH_SHORT).show();
    

提交回复
热议问题