Android Toast Create showToast(final Context ctx, final Handler handler, final String text, final int duration)

Here you can find the source of showToast(final Context ctx, final Handler handler, final String text, final int duration)

Description

Schedule a toast message to be shown via supplied handler.

License

Apache License

Parameter

Parameter Description
handler the handler the toast should be scheduled to
text string for the message text
duration toast duration constant

Declaration

public static void showToast(final Context ctx, final Handler handler,
        final String text, final int duration) 

Method Source Code

//package com.java2s;
/*/* w w  w .  j  a  v  a2s  . c o m*/
 * Copyright (C) 2011 The Android Open Source Project
 *               2013 Grigori Goronzy <greg@chown.ath.cx>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.os.Handler;
import android.content.Context;
import android.widget.Toast;

public class Main {
    /**
     * Schedule a toast message to be shown via supplied handler.
     *
     * @param handler the handler the toast should be scheduled to
     * @param id string resource id for the message text
     * @param duration toast duration constant
     */
    public static void showToast(final Context ctx, final Handler handler,
            final int id, final int duration) {
        handler.post(new Runnable() {
            public void run() {
                Toast.makeText(ctx, id, duration).show();
            }
        });
    }

    /**
     * Schedule a toast message to be shown via supplied handler.
     *
     * @param handler the handler the toast should be scheduled to
     * @param text string for the message text
     * @param duration toast duration constant
     */
    public static void showToast(final Context ctx, final Handler handler,
            final String text, final int duration) {
        handler.post(new Runnable() {
            public void run() {
                Toast.makeText(ctx, text, duration).show();
            }
        });
    }
}

Related

  1. showToast(String text, Context context)
  2. showToast(final Context context, String text)
  3. showToast(final Context context, final String message)
  4. showToast(final Context context, final String string)
  5. showToast(final Context context, final int resId)
  6. showToast(final Context ctx, final Handler handler, final int id, final int duration)
  7. showToast(final String toast, final Context context)
  8. showToast(final String toast, final Context context)
  9. showToastInThread(final Context context, final String msg)