Skip to content Skip to sidebar Skip to footer

Android, Using Toast Inside Onclicklistener

I am trying to make a toast display some text given certain conditions inside an onClickListener. The app won´t run in the simulator, and I get the following error: 'void cannot b

Solution 1:

do it without assignment statement

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

Solution 2:

apply it as.

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

Solution 3:

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

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

Solution 4:

Dear Friend check below before eating Toast,

Your Toast (Incompatible types error) :

Toasttoast= 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):

Viewtoast= 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

Post a Comment for "Android, Using Toast Inside Onclicklistener"