show Toast on UI Thread - Android User Interface

Android examples for User Interface:Toast

Description

show Toast on UI Thread

Demo Code


//package com.java2s;

import android.app.Activity;

import android.widget.Toast;

public class Main {

    public static void show(final Activity activity, final String message,
            final boolean isLong) {
        final String msg = message;
        activity.runOnUiThread(new Runnable() {
            public void run() {
                int duration = Toast.LENGTH_SHORT;
                if (isLong) {
                    duration = Toast.LENGTH_LONG;
                }/* w w w  . j  av a 2s .  c  o m*/

                Toast.makeText(activity, msg, duration).show();
            }
        });
    }

    public static void show(Activity activity, int msgResID) {
        Toast.makeText(activity, msgResID, Toast.LENGTH_SHORT).show();
    }
}

Related Tutorials