当我不能使用“这个”时如何使用Toast作为背景 [英] How to use Toast when I cant use "this" as context

查看:157
本文介绍了当我不能使用“这个”时如何使用Toast作为背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位置监听器活动,我想做吐司通知。但它不会让我传递这个作为上下文。我应该怎样做吐司?

I have a location listener activity and I want to make toast notifications. But it will not let me pass this as the context. How should I make toast work?

推荐答案

如果吐司位于你的活动类中,你可以 YourActiviy.this 其中 YourActivity 是类名。如果它在你的课外,你需要获得你的活动上下文(在构造函数中传递它等)。

If the toast is located inside your activity class, you could yous YourActiviy.this where YourActivity is the class name. if it's outside your class, you'll need to get your activity context (pass it in the constructor etc.)

这篇关于当我不能使用“这个”时如何使用Toast作为背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆