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?
Did you call
super.show()within your override? It’s likely thatToast.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:
Then, when you want to use it, do:
See the Toast docs as a reference when filling this out: http://developer.android.com/reference/android/widget/Toast.html