如何将 toast 从一项活动显示到另一项活动
我有一个问题。是否可以从 HttpDownload 类向 AnimalBadger 类显示 toast 消息(在 if 条件下)? (两个课程都扩展了 Activity)
if (((Node) textNodes.item(i)).getNodeValue().equals("a waning quarter moon"))
{
Toast.makeText(HttpDownload.this, "Some text...", Toast.LENGTH_LONG).show();
}
感谢您的回答......
I have a question. Is it possible to display a toast message (in if condition) from HttpDownload class to AnimalBadger class? (Both classes extend Activity)
if (((Node) textNodes.item(i)).getNodeValue().equals("a waning quarter moon"))
{
Toast.makeText(HttpDownload.this, "Some text...", Toast.LENGTH_LONG).show();
}
Thanks for the answers...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个参数只是获取用于创建 Toast 的 Context。您可以使用 Activity 甚至
getApplicationContext()
。为简单起见,您通常使用最接近的可用上下文,在本例中将是您的包含活动。Toast 不在应用程序组件之间发送,它们通常采用屏幕底部的小通知的形式,是向用户传达低优先级消息的一种方式。
您可能需要阅读文档中的创建 Toast 通知文章。
The first argument is just to get the
Context
to create the Toast with. You can use either activity or evengetApplicationContext()
. For simplicity, you usually use the closest available Context, which in this case would be your containing activity.Toasts are not sent between application components, they take the form of small notifications usually at the bottom of the screen, and are a way to communicate low-priority messages to the user.
You may want to read the Creating Toast Notifications article in the documentation.
您可以使用回调函数并将其注册到 HttpDownload 类。这样,回调就会被调用,这将引发吐司(双关语)。
You could use a call back function and register it with HttpDownload class. That way the call back is called which will throw the toast(pun intended).