Android, using Toast inside onClickListener

旧巷老猫 提交于 2019-12-01 20:14:53

do it without assignment statement

Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();

apply it as.

Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();

if you want to use assignment operator then you can use below code

Toast toast = Toast.makeText(context, text, duration);
toast.show();

Dear Friend check below before eating Toast,

Your Toast (Incompatible types error) :

 Toast toast = Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show(); 

Normal Case (Standard Use):

Toast.makeText(Case1Activity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();`

Special Case (if you need reference of Toast):

 View toast = Toast.makeText(MainActivity.this, "You are doing this in the right order!", Toast.LENGTH_LONG).show();

because here ".show()" method is -

public void show () which shows the view for the specified duration.

Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!