如何从一个屏幕发送字符串值到另一个黑莓? [英] How to send String value from one screen to another in Blackberry?

查看:185
本文介绍了如何从一个屏幕发送字符串值到另一个黑莓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请人帮我从一个屏幕传递字符串值在黑莓另一个屏幕

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

推荐答案

我会说这样做从第一屏推第二屏幕,而不是从应用程序。

在应用程序推第一个画面:

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

二屏幕上显示的字符串值的setter:

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

这篇关于如何从一个屏幕发送字符串值到另一个黑莓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆