我对黑莓应用程序非常陌生。
现在尝试使用 eclipse 在黑莓中创建计算器:
所以我添加了一个按钮(ButtonField
),我的第一个目标是当按下这个按钮时我想要显示
“嗨..现在您可以尝试使用文本字段。”
这里是我的代码,请看一下。
Launcher.java
public class Launcher extends UiApplication {
public static void main(String[] args) {
Launcher theApp = new Launcher();
theApp.enterEventDispatcher();
}
private Launcher()
{
this.pushScreen(new MainScrn());
}
}
MainScrn.java
public class MainScrn extends MainScreen implements FieldChangeListener {
public MainScrn() {
LabelField lf_hello = new LabelField();
lf_hello.setText("Hello, World!");
lf_hello.setBackground(BackgroundFactory.createSolidBackground(124));
ButtonField mySubmitButton = new ButtonField("clickMe");
mySubmitButton.setChangeListener(this);
this.add(lf_hello);
this.add(mySubmitButton);
}
public void fieldChanged(Field field, int context) {
System.out.println("hi.. now you can try with text field");
}
}
你好,这有什么问题吗? ?请帮忙.. 这对你来说很简单,但对我来说不是吗?
最佳答案
在字段更改监听器中,替换此代码
public void fieldChanged(Field field, int context) {
System.out.println("hi.. now you can try with text field");
}
与
public void fieldChanged(Field field, int context) {
if(field == mySubmitButton) {
System.out.println("hi.. now you can try with text field");
}
}
不要只写你想做的事情。首先检查它是否是 ButtonField 然后为其编写代码。
关于黑莓 ButtonField 应用程序示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8164137/