Here you can find the source of showToast(final Context ctx, final Handler handler, final int id, final int duration)
Parameter | Description |
---|---|
handler | the handler the toast should be scheduled to |
id | string resource id for the message text |
duration | toast duration constant |
public static void showToast(final Context ctx, final Handler handler, final int id, final int duration)
//package com.java2s; /*// ww w . j a va2 s . com * 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(); } }); } }