I am trying to run a toast in sequence in order to display a ruuning rss feed. I am getting the following error when running:java.lang.RuntimeException: This Toast was not created with Toast.makeText()
My code is:
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
ImageView image = (ImageView) layout.findViewById(R.id.toastimage);
image.setImageResource(R.drawable.bball_icon);
TextView text = (TextView) layout.findViewById(R.id.toasttext);
Toast toast = new Toast(getApplicationContext());
toast.setView(layout);
for (int i=0;i<episode_titles.size();i++)
{
toast.setText(episode_titles.get(i).toString());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();
}
So basically, Toast. makeText(getBaseContext(),"Your message", Toast. LENGTH_LONG). show(); will generate the toast message and if you want to it to be displayed for some particular case, then just put the condition inside the if statement.
This is what I learnt as things to remember when showing a toast while debugging this issue : Make sure not to forget to call show() after the makeText. Check for the Context , if its the right one. The most important one , make sure your Android Notifications are on for your app, else the Toast will not be shown.
An Example When you send messages from the Gmail application, a toast message appears saying “Sending…”. Once the email is sent, the Toast message changes to “Message sent.” The image below is a screen grab of a Toast message in the Gmail Android application.
To set text to toast, you have to initialize it via makeText
.
Like this:
Toast toast = Toast.makeText(this, "message", Toast.LENGTH_SHORT);
toast.setText("new message");
toast.setGravity(Gravity.CENTER, 0, 0);
//other setters
toast.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With