2009-07-14 3 views

答えて

6

アプリケーションからではなく、第1の画面から第2の画面をプッシュするとします。アプリで
は、最初の画面をプッシュ:

public class App extends UiApplication { 
    public static void main(String[] args) { 
     App app = new App(); 
     app.enterEventDispatcher(); 
    } 
    public App() { 
     FirstScreen scr = new FirstScreen(); 
     pushScreen(scr); 
    } 
} 

第2のスクリーンは、文字列値の設定部を有する第一の画面において

public class SecondScreen extends MainScreen { 

    String mTextValue = null; 
    LabelField mLabel = null; 

    public void setTextValue(String textValue) { 
     mTextValue = textValue; 
     mLabel.setText(mTextValue); 
    } 

    public SecondScreen() { 
     super();   
     mLabel = new LabelField(); 
     add(mLabel); 
    } 
} 

第二セットの文字列値を作成し、それを押します。あなたがそれを返す必要がない場合は、最初の画面をポップアップ:

public class FirstScreen extends MainScreen implements FieldChangeListener { 

    BasicEditField mEdit = null; 
    ButtonField mButton = null; 

    public FirstScreen() { 
     super();     
     mEdit = new BasicEditField("input: ", "some text"); 
     add(mEdit); 
     mButton = new ButtonField("Go second screen"); 
     mButton.setChangeListener(this); 
     add(mButton); 
    } 
    public void fieldChanged(Field field, int context) { 
     if(mButton == field) 
     { 
      SecondScreen scr = new SecondScreen(); 
      scr.setTextValue(mEdit.getText()); 
      UiApplication.getUiApplication().pushScreen(scr); 
      UiApplication.getUiApplication().popScreen(this); 
     } 
    } 
} 
+0

良い例の仲間+1 –

2

私は、あなたが必要とするものをもう少し明確にする必要があるかもしれないと思います。しかし、あなたの元の質問を文字どおりに取ると、コードの次のビットはあなたがそれをやる方法です。

public class MyApp extends UiApplication { 
    MyApp() { 
    MyFirstScreen screenOne = new MyFirstScreen(); 
    pushScreen(screenOne); 
    String str = screenOne.getWhateverStringINeed(); 
    MySecondScreen screenTwo = new MySecondScreen(str); 
    pushScreen(screenTwo); 
    } 
} 

上記のコードは、第2のスクリーンは、本質的に最初の画面から、(必要に起こる何列)列を有する、BlackBerryの表示スタックに二つの画面を押すことになります。

関連する問題