I\'m trying to use Toast
inside OnCLickListener
. My code triggers the following error:
The method makeText(Context, CharSequence, int)
Anywhere, just use the following:
((Activity) mContext).runOnUiThread(new Runnable() {
public void run() {
Toast my_toast = Toast.makeText(mContext, "YOUR TEXT OR STRING", Toast.LENGTH_LONG);
my_toast.setGravity(Gravity.CENTER, 0, 0);
my_toast.show();
}
});
You just need to define at the top of your activity (just after the onCreate):
mContext = this;
Also, see that I decomposed it a bit to be able to handle the gravity as I want (sometimes you may want the toast to appear at the center of the screen)...