Error due to invalid combination of Toast and OnClickListener

前端 未结 7 1960
醉梦人生
醉梦人生 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();
        }
    

提交回复
热议问题