在非活动类中使用Activity方法

时间:2015-04-20 16:51:58

标签: java android

我正在尝试通过非Activity类向Activity写一个表,但我无法访问Activity方法这样做。
我通过构造函数传递了Activity,但像findViewById这样的方法仍然没有工作 我认为我需要setContextView

这种方法是否正确?如果是这样,我在课堂上作为setContextView的论据放在哪里,我该怎么做?

以下是我正在采取的方法,但我不确定如何使用setContextView以便可以使用findViewById等活动方法。

MyClass instance = new MyClass(this);

public class MyClass {
    public Activity activity;

    public MyClass(Activity _activity){
        this.activity = _activity;
    }
}

1 个答案:

答案 0 :(得分:0)

根据您的代码,您可以调用所有活动方法:

activity.findVewById(R.xxx.xxx);
activity.getResrouces();
etc...