//Displays Toast for a short period of time
Toast.makeText(getApplicationContext(),”Message you want to display”, Toast.LENGTH_SHORT).show();
//Displays Toast for a longer period of time
Toast.makeText(getApplicationContext(),”Message you want to display”, Toast.LENGTH_LONG).show();
In this case get this toast code in the separate file
public static void toasty(Context con, String msg)
{
Toast.makeText(con, msg, Toast.LENGTH_LONG).show(); } Call this method from your activities to reuse the code. Here AppUtilities is the class name where our method is written. AppUtilies.toasty(getApplicationContext(), “Please enter an email and password”); |
Advertisements