Sunday, July 28, 2013

Android Simple Toast Example


SIMPLE TOAST


To display a simple toast, we need to makeText for that toast & then call show() to display it.
To use makeText(), we need to send 3 arguments.
1) Context
2) Text to display in toast
3) Duration How much time its need to be show
At last call show() to display toast.


SOURCE CODE is

package com.ToastExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class ToastExample extends Activity
{
                public void onCreate(Bundle savedInstanceState)
                {
                                super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);

                                 Toast msg = Toast.makeText(ToastExample.this,
                                                "YOUR TEXT HERE", Toast.LENGTH_LONG);
                                msg.show();

                 }
}



The OUTPUT will be


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRKt64VP005Qe_pya6t4J9Eh4jwDPWWn1MlprdH5QH0EGHRFnKIAx_WRsR8I0Vh5Kzmlz4A-Jy8YTfhUbwO8ncKSXZaTpPA9WUyTVjHa5E8WVPUamPqb_kl6ca8mGt0WYzayE3MGAsIjM/