Build 1.0_r1(from source)

android.widget
Class Toast

java.lang.Object
  extended by android.widget.Toast

public class Toast
extends Object

A toast is a view containing a quick little message for the user. The toast class helps you create and show those.

When the view is shown to the user, appears as a floating view over the application. It will never receive focus. The user will probably be in the middle of typing something else. The idea is to be as unobtrusive as possible, while still showing the user the information you want them to see. Two examples are the volume control, and the brief message saying that your settings have been saved.

The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new Toast object.


Field Summary
static int LENGTH_LONG
          Show the view or text notification for a long period of time.
static int LENGTH_SHORT
          Show the view or text notification for a short period of time.
(package private) static boolean localLOGV
           
(package private)  Context mContext
           
(package private)  int mDuration
           
(package private)  int mGravity
           
(package private)  Handler mHandler
           
(package private)  float mHorizontalMargin
           
(package private)  View mNextView
           
(package private)  android.widget.Toast.TN mTN
           
(package private)  float mVerticalMargin
           
(package private)  View mView
           
(package private)  int mX
           
(package private)  int mY
           
(package private) static String TAG
           
 
Constructor Summary
Toast(Context context)
          Construct an empty Toast object.
 
Method Summary
 void cancel()
          Close the view if it's showing, or don't show it if it isn't showing yet.
 int getDuration()
          Return the duration.
 int getGravity()
          Get the location at which the notification should appear on the screen.
 float getHorizontalMargin()
          Return the horizontal margin.
 float getVerticalMargin()
          Return the vertical margin.
 View getView()
          Return the view.
 int getXOffset()
          Return the X offset in pixels to apply to the gravity's location.
 int getYOffset()
          Return the Y offset in pixels to apply to the gravity's location.
static Toast makeText(Context context, CharSequence text, int duration)
          Make a standard toast that just contains a text view.
static Toast makeText(Context context, int resId, int duration)
          Make a standard toast that just contains a text view with the text from a resource.
 void setDuration(int duration)
          Set how long to show the view for.
 void setGravity(int gravity, int xOffset, int yOffset)
          Set the location at which the notification should appear on the screen.
 void setMargin(float horizontalMargin, float verticalMargin)
          Set the margins of the view.
 void setText(CharSequence s)
          Update the text in a Toast that was previously created using one of the makeText() methods.
 void setText(int resId)
          Update the text in a Toast that was previously created using one of the makeText() methods.
 void setView(View view)
          Set the view to show.
 void show()
          Show the view for the specified duration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG

static final String TAG
See Also:
Constant Field Values

localLOGV

static final boolean localLOGV
See Also:
Constant Field Values

LENGTH_SHORT

public static final int LENGTH_SHORT
Show the view or text notification for a short period of time. This time could be user-definable. This is the default.

See Also:
setDuration(int), Constant Field Values

LENGTH_LONG

public static final int LENGTH_LONG
Show the view or text notification for a long period of time. This time could be user-definable.

See Also:
setDuration(int), Constant Field Values

mContext

final Context mContext

mTN

final android.widget.Toast.TN mTN

mDuration

int mDuration

mGravity

int mGravity

mX

int mX

mY

int mY

mHorizontalMargin

float mHorizontalMargin

mVerticalMargin

float mVerticalMargin

mView

View mView

mNextView

View mNextView

mHandler

final Handler mHandler
Constructor Detail

Toast

public Toast(Context context)
Construct an empty Toast object. You must call setView(android.view.View) before you can call show().

Parameters:
context - The context to use. Usually your Application or Activity object.
Method Detail

show

public void show()
Show the view for the specified duration.


cancel

public void cancel()
Close the view if it's showing, or don't show it if it isn't showing yet. You do not normally have to call this. Normally view will disappear on its own after the appropriate duration.


setView

public void setView(View view)
Set the view to show.

See Also:
getView()

getView

public View getView()
Return the view.

See Also:
setView(android.view.View)

setDuration

public void setDuration(int duration)
Set how long to show the view for.

See Also:
LENGTH_SHORT, LENGTH_LONG

getDuration

public int getDuration()
Return the duration.

See Also:
setDuration(int)

setMargin

public void setMargin(float horizontalMargin,
                      float verticalMargin)
Set the margins of the view.

Parameters:
horizontalMargin - The horizontal margin, in percentage of the container width, between the container's edges and the notification
verticalMargin - The vertical margin, in percentage of the container height, between the container's edges and the notification

getHorizontalMargin

public float getHorizontalMargin()
Return the horizontal margin.


getVerticalMargin

public float getVerticalMargin()
Return the vertical margin.


setGravity

public void setGravity(int gravity,
                       int xOffset,
                       int yOffset)
Set the location at which the notification should appear on the screen.

See Also:
Gravity, getGravity()

getGravity

public int getGravity()
Get the location at which the notification should appear on the screen.

See Also:
Gravity, getGravity()

getXOffset

public int getXOffset()
Return the X offset in pixels to apply to the gravity's location.


getYOffset

public int getYOffset()
Return the Y offset in pixels to apply to the gravity's location.


makeText

public static Toast makeText(Context context,
                             CharSequence text,
                             int duration)
Make a standard toast that just contains a text view.

Parameters:
context - The context to use. Usually your Application or Activity object.
text - The text to show. Can be formatted text.
duration - How long to display the message. Either LENGTH_SHORT or LENGTH_LONG

makeText

public static Toast makeText(Context context,
                             int resId,
                             int duration)
                      throws Resources.NotFoundException
Make a standard toast that just contains a text view with the text from a resource.

Parameters:
context - The context to use. Usually your Application or Activity object.
resId - The resource id of the string resource to use. Can be formatted text.
duration - How long to display the message. Either LENGTH_SHORT or LENGTH_LONG
Throws:
Resources.NotFoundException - if the resource can't be found.

setText

public void setText(int resId)
Update the text in a Toast that was previously created using one of the makeText() methods.

Parameters:
resId - The new text for the Toast.

setText

public void setText(CharSequence s)
Update the text in a Toast that was previously created using one of the makeText() methods.

Parameters:
s - The new text for the Toast.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature