我正在尝试按顺序运行toast以显示ruuning rss feed.运行时出现以下错误:java.lang.RuntimeException:此Toast未使用Toast.makeText()创建
我的代码是:
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();
}
Run Code Online (Sandbox Code Playgroud)
san*_*one 18
要将文本设置为toast,您必须通过它进行初始化makeText.
像这样:
Toast toast = Toast.makeText(this, "message", Toast.LENGTH_SHORT);
toast.setText("new message");
toast.setGravity(Gravity.CENTER, 0, 0);
//other setters
toast.show();
Run Code Online (Sandbox Code Playgroud)
Toast U 可以这样指定...
Toast.makeText(getApplicationContext(), "hai", Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
那么你可以这样写...
String s=episode_titles.get(i).toString();
Toast.makeText(getApplicationContext(), "UrMessage:"+s, Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10089 次 |
| 最近记录: |