如何在黑莓中将字符串值从一个屏幕发送到另一个屏幕?

发布于 2024-07-27 02:06:44 字数 35 浏览 2 评论 0原文

任何人请帮助我将字符串值从黑莓的一个屏幕传递到另一个屏幕

Anyone please help me to pass String value from one screen to another screen in Blackberry

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

享受孤独 2024-08-03 02:06:45

我想说从第一个屏幕推动第二个屏幕,而不是从应用程序。
在应用程序中推送第一个屏幕:

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

第二个屏幕有一个字符串值设置器:

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

I would say to do pushing 2nd screen from the 1st screen, not from the application.
In app push first screen:

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

Second screen has a setter for string value:

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

In first screen create second, set string value and push it. Pop first screen if you don't need to return on it:

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);
        }
    }   
}
伴梦长久 2024-08-03 02:06:45

我认为您可能需要更清楚地了解您的需求。 但从字面上看你原来的问题,下面的代码就是你将如何做到这一点。

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

上面的代码会将两个屏幕推送到 BlackBerry 显示堆栈上,第二个屏幕基本上包含第一个屏幕中的字符串(无论您需要什么字符串)。

I think you may need to be a little more clear in what you require. But taking your original question literally, the following bit of code is how you would do it.

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

The above code would push two screens onto the BlackBerry display stack, with the second screen essentially having the string (whatever string you happen to need), from the first screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文