1

誰でも、Blackberryのある画面から別の画面に文字列値を渡すのを手伝ってください

4

2 に答える 2

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);
    }
}

最初の画面で2番目に作成し、文字列値を設定してプッシュします。戻る必要がない場合は、最初の画面をポップします。

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);
        }
    }   
}
于 2009-07-15T06:57:55.437 に答える