Toast myToast = Toast.makeText(this, "I'm a toast!", Toast.LENGTH_LONG);
myToast.show();
// Toast in Adapter
// in onBindViewHolder()
Toast.makeText(holder.itemview.getContext, "Your Toast Msg Here! ",
Toast.LENGTH_LONG).show();
// in view holder
Toast.makeText(itemview.getContext, "Your Toast Msg Here! ",
Toast.LENGTH_LONG).show();
// if you are already taking context in adapter's constructor
// then you can do like this
Toast.makeText(context, "Your Toast Msg Here! ",
Toast.LENGTH_LONG).show();
// Short form - Work in Kotlin
Toast.makeText(this, text: "Hello World", Toast.LENGTH_LONG).show()
Toast toast;
private void toast(String msg) {
if (toast != null) toast.cancel();
toast = Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT);
toast.show();
}
String toastTextMsg = "Hello, welcome to Code2care!";
Toast toast = Toast.makeText(MainActivity.this, toastTextMsg , Toast.LENGTH_SHORT);
toast.show();
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();