Example usage for android.widget Toast Toast

List of usage examples for android.widget Toast Toast

Introduction

In this page you can find the example usage for android.widget Toast Toast.

Prototype

public Toast(Context context) 

Source Link

Document

Construct an empty Toast object.

Usage

From source file:com.kll.collect.android.activities.FormEntryActivity.java

/**
 * Creates a toast with the specified message.
 *
 * @param message/*from  w  ww.j a v  a2 s .c o m*/
 */
private void showCustomToast(String message, int duration) {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.toast_view, null);

    // set the text in the view
    TextView tv = (TextView) view.findViewById(R.id.message);
    tv.setText(message);

    Toast t = new Toast(this);
    t.setView(view);
    t.setDuration(duration);
    t.setGravity(Gravity.CENTER, 0, 0);
    t.show();
}

From source file:org.smilec.smile.student.CourseList.java

public void showToast(String msg) {
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root));

    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText(msg);// www  .  j  a  va2  s.  co m

    Toast toast = new Toast(getApplicationContext());
    if (smile.face != null)
        text.setTypeface(smile.face);
    text.setText(msg);
    toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 100);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
}