2011-08-01 27 views
0

現在、ブラックベリーアプリを開発中です。シナリオは、ユーザーがメニュー項目をクリックすると、別のページに移動します。現在、MyApp、SecondPage、およびMyScreenの3つのクラスがあります。以下のコードはSecondPageに属します。BlackBerryのページ/クラスを切り替える

MyAppから、ユーザーがMenuItemをクリックした後にpushScreenをSecondPageにしようとしていますが、(SecondPage)がUiApplicationを拡張しているため、できません。 MainScreenを拡張するためにそれを変更すると、pushScreen(_screen)を実行できなくなります。どのような提案をお願いしますか?

おかげで、 HEND

class MyApp extends UiApplication{ 

//creating a member variable for the MainScreen 
MainScreen _screen= new MainScreen(); 
//string variables to store the values of the XML document 
String _node,_element; 
Connection _connectionthread; 

public static void main(String arg[]){ 
    MyApp application = new MyApp(); 
    //create a new instance of the application 
    //and start the application on the event thread 
    application.enterEventDispatcher(); 
} 

public MyApp() { 
    _screen.setTitle("Agenda");//setting title 
    //_screen.add(new RichTextField("Requesting.....")); 
    _screen.add(new SeparatorField()); 
    pushScreen(_screen); // creating a screen 
    //creating a connection thread to run in the background 
    _connectionthread = new Connection(); 
    _connectionthread.start();//starting the thread operation 
} 

    public void updateField(String node, String element) 
{  
    synchronized (UiApplication.getEventLock()) 
    { 
     String title = "My App"; 
     _screen.add(new RichTextField(/*node + " : " +*/ element + "\n")); 
     if (node.equals(title)) 
     { 
      _screen.add(new SeparatorField()); 
     } 
    } 
} 

答えて

1

はあなたの画面がスクリーンから、ではないのUIApplicationから継承する必要があります。 UiApplicationのドキュメントを見ると、静的メソッドgetUiApplication()があることがわかります。このメソッドは、(他の便利なタスクの中でも)画面をプッシュする目的でUiApplicationへの参照を返します。

pushScreen(_screen)の代わりに、コードはUiApplication.getUiApplication().pushScreen(_screen)となります。