Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7127943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:05:11+00:00 2026-05-28T11:05:11+00:00

I just need to override the show() method for the Toast class. I created

  • 0

I just need to override the show() method for the Toast class. I created a class which extends Toast class, but then I create a toast message I get an exception the setView(View view) hasn’t been called. But I don’t want to create a custom View for the method but use the default one.

So, how is that possible to override the only show() method without creation of custom View for the setView(View view) method?

Here is what I do:

 MyOwnToast m = new MyOwnToast(getApplicationContext());
        m.makeText(getApplicationContext(), "Bla bla bla", Toast.LENGTH_LONG);
        m.show();

And my custom toast is here:

public class MyOwnToast extends Toast {
    public MyOwnToast(Context context) {
        super(context);
    }

    @Override
    public void show() {
        super.show();
        Log.i("Dev", "
}

Also it is stated on the dev site:

Note: Do not use the public constructor for a Toast unless you are
going to define the layout with setView(View). If you do not have a
custom layout to use, you must use makeText(Context, int, int) to
create the Toast.

How I can override the show() method then?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:05:11+00:00Added an answer on May 28, 2026 at 11:05 am

    Did you call super.show() within your override? It’s likely that Toast.show() is calling this, and your override is now making it so that the call doesn’t happen.

    What you’ll probably need to do is something like this:

    public class MyOwnToast extends Toast {
        public MyOwnToast(Toast toast) {
            //Code to initialize your toast from the argument toast
    
            //Probably something like this:
            this.setView(toast.getView());
            this.setDuration(toast.getDuration());
            //etc. for other get/set pairs in Toast
        }
    
        public static MyMakeText(Context context, CharSequence text, int duration) {
            return new MyOwnToast(Toast.makeText(context, text, duration));
        }
    
        public void show() {
            //Your show override code, including super.show()
        }
    }
    

    Then, when you want to use it, do:

    MyOwnToast.MyMakeText(activity, "Some text", Toast.LENGTH_LONG).show();
    

    See the Toast docs as a reference when filling this out: http://developer.android.com/reference/android/widget/Toast.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just need get some vals located in application.ini(main ini) in the Controller plugin I
I just need to know hot to create a CGLayer that has an image
I have read that when you override Equals on an class/object you need to
Basically I want to override some function in the flex/actionscript list class which creates
Just need a little bit of Javascript to warn people that press the back
I just need a file (picture, pdf or other type file for printing) of
I just need to know if WCF is platform independent like Webservices? Can the
I just need to be pointed in the right direction - I can research
I just need some clarification on variables A normal variable has 2 parts to
I just need to rename JQgrid column dynamically as per user selection from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.