Skip to content Skip to sidebar Skip to footer

Toast Inside A Button Onclicklistener Is Not Working

intdelay was initialized at the beginning of the code by 1000. and I am trying to make sure that intdelay's value is updated by the value in the edit box by adding a toast when the

Solution 1:

You have given wrong context; change this line:

 Toast.makeText(this,"your integer is " + intdelay , Toast.LENGTH_LONG).show();

to

 Toast.makeText(YourActivity.this,"your integer is " + intdelay , Toast.LENGTH_LONG).show();

Solution 2:

That's because makeText wants to have a Context as a first argument. You are inside the onClick function of an OnClickListener. This means that this points to your OnClickListener. You must have something like this

Toast.makeText(YourActivity.this,"your integer is " + intdelay , Toast.LENGTH_LONG).show();

Solution 3:

Try like this:

Toast.makeText(YourActivityName.this,"your integer is " + intdelay , Toast.LENGTH_LONG).show();

Solution 4:

Change the context if not somwthing may wrong in flashLight.switchFlash method

Solution 5:

You are trying to show your toast inside the OnClickListener. The this keyword in this case refers to an instance of type OnClickListener, and not Context, like it is required.

You should use <YourActivityClass>.this to refer to the enclosing activity instance, that is a Context and can be use to show the toast.

Post a Comment for "Toast Inside A Button Onclicklistener Is Not Working"