Error due to invalid combination of Toast and OnClickListener

前端 未结 7 1953
醉梦人生
醉梦人生 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条回答
  • 2021-01-31 09:20

    try this

     public void onClick(View arg0) {
            EditText name = (EditText)findViewById(R.id.name);
            String Lname = name.getText().toString();
            Toast.makeText(arg0.getContext(), Lname, Toast.LENGTH_SHORT).show();
        }
    
    0 讨论(0)
提交回复
热议问题