2011-11-03 64 views
1

我来自Android,现在我正在学习黑莓。黑莓 - 访问其他类实例上下文

在Android中访问其他类,我们可以在java中传递它的上下文类似的“this”。黑莓手机怎么做?问题是在黑莓我想补充其他类屏类的字段/经理,例如代码:

public final class MyScreen extends MainScreen 
{ 
//Creates a new MyScreen object 

    public MyScreen() 
    {   
    // Set the displayed title of the screen  
    setTitle("MyTitle"); 
    process1 x = new process1(); // will add the labelfield 
    } 
} 

这在其他文件类

public class process1 
{ 
    public process1() 
    {   
    //i'm trying to get the context of MyScreen so i can add the field in this class 
    MyScreen.add(new Labelfield("test")); 
    //but its giving error with the message cannot make static reference 
    } 
} 

回答

3

变化的过程1构造函数调用构造函数时

public process1(MyScreen screen) 
    {   
    screen.add(new Labelfield("test")); 
    } 
+0

并使用'this':采取自选对象'过程1 X =新过程1(本);' –

+0

感谢,为什么没有我以前想这一点。 :d – Pasca