如何从类没有延伸活动显示敬酒消息消息

由网友(伤心的眼泪谁来安慰)分享简介:可能重复: How做我做从非活性类举杯? 我如何创建并显示一个吐司消息不延长活动类的类?我在由活动。How can I create and show a Toast message from a class which does not extended the Activity class? I'm usin...

可能重复:   How做我做从非活性类举杯?

我如何创建并显示一个吐司消息不延长活动类的类?我在由活动

How can I create and show a Toast message from a class which does not extended the Activity class? I'm using this class in another class that is extended by Activity.

推荐答案

您需要一个背景参考。您可以在创建类明确作为参数传递

You need a context Reference. you can explicit pass as parameter when you create your class

public class MyClass {

  private static Context context;
  public MyClass(Context c) {
     context = c;
  }

  public static void showToastMethod() {
        Toast.makeText(context, "mymessage ", Toast.LENGTH_SHORT).show();
  }

}
阅读全文

相关推荐

最新文章