Toast makeText - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Toast makeText method.

This code example shows how to use the following methods:finish, startActivity, setClass, makeText
 
    protected void onPostExecute(String message) {
        dialog.hide();
        dialog.cancel();
 
        Toast.makeText(context,message,Toast.LENGTH_LONG).show();
 
		Intent i = new Intent().setClass(context, TabWidget.class);
		context.startActivity(i);
 
        context.finish();
    } 
} 
7
CodeRank
This code example shows how to use the following methods:finish, makeText
    } 
     
    @Override 
    protected void onPostExecute(Void unused) {
      if (text!=null) {
        Toast.makeText(host, text, Toast.LENGTH_SHORT).show();
      } 
       
      host.finish();
    } 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:getResources, makeText
 
        final Context context = view.getContext();
        final int viewWidth = view.getWidth();
        final int viewHeight = view.getHeight();
        final int viewCenterX = screenPos[0] + viewWidth / 2;
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        final int estimatedToastHeight = (int) (ESTIMATED_TOAST_HEIGHT_DIPS
                * context.getResources().getDisplayMetrics().density);
 
        Toast cheatSheet = Toast.makeText(context, text, Toast.LENGTH_SHORT);
        boolean showBelow = screenPos[1] < estimatedToastHeight;
        if (showBelow) {
            // Show below 
            // Offsets are after decorations (e.g. status bar) are factored in 
            cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL,
                    viewCenterX - screenWidth / 2,
                    screenPos[1] - displayFrame.top + viewHeight);
        } else { 
            // Show above 
            // Offsets are after decorations (e.g. status bar) are factored in 
7
CodeRank
This code example shows how to use the following methods:runOnUiThread, getString, makeText
     * @param resId The resource identifier of the message string 
     * @param formatArgs The format arguments that will be used for substitution. 
     */ 
    public static void showToast( Activity activity, int resId, Object... formatArgs )
    { 
        showToast( activity, activity.getString( resId, formatArgs ) );
    } 
     
    /** 
     * Pop up a temporary message on the device. 
     * @param activity The activity to display from 
     * @param message The message string to display. 
     */ 
    public static void showToast( Activity activity, String message )
    { 
        if( activity == null )
            return; 
         
        if( sToast != null )
        { 

7
CodeRank
This code example shows how to use the following methods:getString, makeText
 
	private NotificationUtil() { 
	} 
 
	public static void makeToast(Context context, int resId) {
		makeToast(context, context.getString(resId));
	} 
 
	public static void makeToast(Context context, String message) {
		Toast.makeText(context, message, Toast.LENGTH_LONG).show();
	} 
 
	public static void makeServerErrorToast(Context context) {
		makeToast(context, R.string.http_error);
	} 
 
	public static void makeServerErrorToast(Context context, String message) {
		makeToast(context,
				message + ", " + context.getString(R.string.http_error));
	} 
7
CodeRank
This code example shows how to use the following methods:getString, makeText
 
    public static void showToast(Context context, int stringResId) {
        showToast(context, stringResId, Duration.SHORT);
    } 
    public static void showToast(Context context, int stringResId, Duration duration) {
        showToast(context, context.getString(stringResId), duration);
    } 
 
    public static void showToast(Context context, String text) {
        showToast(context, text, Duration.SHORT);
    } 
    public static void showToast(Context context, String text, Duration duration) {
        Toast toast = Toast.makeText(context, text, (duration== Duration.SHORT ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getSharedPreferences, startActivity, makeText
		} else if (intent.getStringExtra("unregistered") != null) {
			Log.d("c2dm", "unregistered");
 
		} else if (registration != null) {
 
			Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
			editor.putString(REGISTRATION_KEY, registration);
			System.out.println(registration);
			editor.commit();
 
			Intent accountIntent = new Intent(context,AccountList.class);
			accountIntent.putExtra("regKey",registration) ;
			accountIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
			context.startActivity(accountIntent);
		} 
		Toast.makeText(context, registration, Toast.LENGTH_LONG);
	} 
 
	private void handleMessage(Context context, Intent intent)
	{ 
		Log.v(TAG,"handleMessage");
6
CodeRank
This code example shows how to use the following methods:getBroadcast, getSystemService, makeText
		super.onDeleted(context, appWidgetIds);
	} 
 
	@Override 
	public void onDisabled(Context context) {
		Toast.makeText(context, "onDisabled():last widget instance removed", Toast.LENGTH_SHORT).show(); 
		Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
		PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
		AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
		alarmManager.cancel(sender);
		super.onDisabled(context);
	} 
 
	@Override 
	public void onEnabled(Context context) {
		super.onEnabled(context);
		AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
		Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
		PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
		//After after 3 seconds 
7
CodeRank
This code example shows how to use the following methods:getString, makeText
     * Displays an error message with a provided error message string. 
     * @param error The error message string to be displayed. 
     */ 
    public void showError(String error) {
        if (error != null) {
            Toast.makeText(mActivity, error, Toast.LENGTH_SHORT).show();
        } 
    } 
 
    /** 
     * Displays an error message from the given resource id. 
     * @param resId The error message string's resource id. 
     */ 
    public void showError(int resId) {
        showError(mActivity.getString(resId));
    } 
 
    /** 
     * Displays an error message for a nonexistent callback. 
     * @param error The error message string to be displayed. 
6
CodeRank
This code example shows how to use the following methods:getPackageManager, makeText
                        "dev/total-conversion-build.user.js not found. " + 
                        "Disable developer mode or add iitc files to the dev folder.", 
                        Toast.LENGTH_LONG).show();
                return; 
            } else { 
                Toast.makeText(mContext, "Developer mode enabled",
                        Toast.LENGTH_SHORT).show();
            } 
        } else { 
            // load iitc script from web or asset folder 
            if (iitc_source.contains("http")) {
                URL url = new URL(iitc_source);
                // if parsing of the online iitc source timed out, use the script from assets 
                try { 
                    js = new UrlContentToString().execute(url).get(5, TimeUnit.SECONDS);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    js = this.fileToString("total-conversion-build.user.js", true);
                } catch (ExecutionException e) {
                    e.printStackTrace();

7
CodeRank

Related Toast makeText Questions & Answers:

Other Toast makeText Examples

41:	  @Override
42:	  public boolean onOptionsItemSelected(MenuItem item) {
43:	    Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
44:	    return true;
45:	  }

Read More

62:	  public void onClick(View view) {
63:	    if (s != null) {
64:	      Toast.makeText(this, "Number of elements" + s.getWordList().size(),
65:	          Toast.LENGTH_SHORT).show();
66:	      wordList.clear();

Read More

72:	  @Override
73:	  public void onProviderEnabled(String provider) {
74:	    Toast.makeText(this, "Enabled new provider " + provider,
75:	        Toast.LENGTH_SHORT).show();
76:	
-
79:	  @Override
80:	  public void onProviderDisabled(String provider) {
81:	    Toast.makeText(this, "Disabled provider " + provider,
82:	        Toast.LENGTH_SHORT).show();
83:	  }

Read More

65:						new AddNewCategory().execute(newCategory);
66:					} else {
67:						Toast.makeText(getApplicationContext(),
68:								"Please enter category name", Toast.LENGTH_SHORT)
69:								.show();

Read More

40:						new AddNewCategory().execute(newCategory);
41:					} else {
42:						Toast.makeText(getApplicationContext(),
43:								"Please enter category name", Toast.LENGTH_SHORT)
44:								.show();

Read More

74:			// Checking camera availability
75:			if (!isDeviceSupportCamera()) {
76:				Toast.makeText(getApplicationContext(),
77:						"Sorry! Your device doesn't support camera",
78:						Toast.LENGTH_LONG).show();
-
162:				} else if (resultCode == RESULT_CANCELED) {
163:					// user cancelled Image capture
164:					Toast.makeText(getApplicationContext(),
165:							"User cancelled image capture", Toast.LENGTH_SHORT)
166:							.show();
-
167:				} else {
168:					// failed to capture image
169:					Toast.makeText(getApplicationContext(),
170:							"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
171:							.show();
-
178:				} else if (resultCode == RESULT_CANCELED) {
179:					// user cancelled recording
180:					Toast.makeText(getApplicationContext(),
181:							"User cancelled video recording", Toast.LENGTH_SHORT)
182:							.show();
-
183:				} else {
184:					// failed to record video
185:					Toast.makeText(getApplicationContext(),
186:							"Sorry! Failed to record video", Toast.LENGTH_SHORT)
187:							.show();

Read More

8:	    gridview.setOnItemClickListener(new OnItemClickListener() {
9:	        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
10:	            Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
11:	        }
12:	    });

Read More

makeText Method Overview
Make a standard toast that just contains a text view with the text from a resource.
See Code Examples for other Android Toast Methods: