Cannot resolve maketext() method of Toast

后端 未结 18 1272
南笙
南笙 2021-02-07 02:02

I am getting error while creating a Toast

Toast toast = Toast.makeText(this, text, duration);

I am getting cannot resolve ma

18条回答
  •  你的背包
    2021-02-07 02:35

    Was having similar issue too but

    getContext()
    

    did the trick for me

    // If message field is empty show a toast and alert the user
    if (TextUtils.isEmpty(message)) {
       Toast.makeText(getContext(),"Please Enter a message", Toast.LENGTH_SHORT).show();
       return;
    }
    

提交回复
热议问题