黑莓 JDE FieldChangeListener

发布于 2024-08-04 11:41:35 字数 842 浏览 4 评论 0原文

我对如何在 Blackberry JDE 中实现 FieldChangeListener 感到有点困惑。一种方法是让我的主类实现 FieldChangeListener,然后在其中添加一个 fieldchanged 方法,另一种方法是让我这样做:

    FieldChangeListener listenerUS = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
System.out.println("Something changed!");
pushScreen(_newScreen);
}
};

无论哪种方式,如果我尝试调用一个方法(例如 PushScreen,或我编写的自定义方法) ,我收到运行时错误。在调试模式下,我的打印语句也没有被显示。但是,如果我完全删除 fieldChanged 方法,它甚至不会编译,所以我相当确定它看到了代码?

我已将侦听器添加到我希望它连接的按钮要么通过:(

            but_temp.setChangeListener(this);

在第一种情况下),要么通过将listenerUS.

一切似乎都连接起来,但是我的打印语句出现了,如果我调用一个方法,我会得到一个运行时错误,

这有意义吗?只是完全不知道如何在黑莓上使用侦听器?

http://pastie.org/618950

有一个副本我的代码作为一个整体......

I'm sort of confused as to how to implement a FieldChangeListener in the Blackberry JDE. One way has me make my main class implement FieldChangeListener, and then have a fieldchanged method inside of it, and another has me do:

    FieldChangeListener listenerUS = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
System.out.println("Something changed!");
pushScreen(_newScreen);
}
};

Either way, if I try to call a method (like pushScreen, or a custom method I've written), I get a runtime error. In debug mode, none of my print statements are being displayed, either. However, if I remove the fieldChanged method outright, it won't even compile, so I"m pretty sure it's seeing the code?

I've added the listener to the button I want it hooked up to either by having:

            but_temp.setChangeListener(this);

(in the first case) or by putting listenerUS.

Everything seems to be hooked up, but of my print statements show up, and if I call a method, I get a runtime error.

Does this make sense? Am I just completely confused about how to use listeners on the blackberry?

http://pastie.org/618950

There's a copy of my code as a whole...

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

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

发布评论

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

评论(3

笨笨の傻瓜 2024-08-11 11:41:35

我看了你的代码,没有发现任何明显的错误。但是,我不会指定主应用程序类承担 FieldChangeListener 的职责。这不是它应该意识到的事情。我能为您做的最好的事情就是提供一个为 ButtonField 实现 FieldChangeListener 接口的示例应用程序。这不是一个解决方案,但也许随着您对代码的更好了解,您将能够挑选出与此示例不同的内容。希望有帮助。

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.FieldChangeListener;

/**
 * Test implementation of ButtonField.
 */
public class TestAppMain extends UiApplication 
{
    /**
     * Default Constructor.
     */
    private TestAppMain() {        
        pushScreen(new AppScreen());
    }

    /**
     * App entry point.
     * @param args Arguments.
     */
    public static void main(String[] args) {
        TestAppMain app = new TestAppMain();
        app.enterEventDispatcher();
    }

    /**
     * Main application screen.
     */
    private static class AppScreen extends MainScreen 
    {
        /**
         * Default constructor.
         */
        public AppScreen() {
            LabelField title = new LabelField("Button Test Demo",
                    LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
            setTitle(title);

            // Create a button with a field change listener.
            FieldChangeListener listener = new FieldChangeListener() {
                public void fieldChanged(Field field, int context) {
                    ButtonField buttonField = (ButtonField) field;
                    System.out.println("Button pressed: " + buttonField.getLabel());
                }
            };
            ButtonField buttonField = new ButtonField("Test Button", ButtonField.CONSUME_CLICK);            
            buttonField.setChangeListener(listener);
            add(buttonField);
        }               

        /**
         * Handle app closing.
         */
        public void close() {
            Dialog.alert("Goodbye!");
            System.exit(0);
            super.close();
        }
    }
}

I looked at your code and nothing blatantly wrong jumped out at me. However, I wouldn't designate the main application class the duties of being the FieldChangeListener. It's not something it should have to be aware of. The best I can do for you is provide an example app that implements the FieldChangeListener interface for a ButtonField. It's not a solution but maybe with your better knowledge of your code you'll be able to pick something out that is different than this example. Hope it helps.

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.FieldChangeListener;

/**
 * Test implementation of ButtonField.
 */
public class TestAppMain extends UiApplication 
{
    /**
     * Default Constructor.
     */
    private TestAppMain() {        
        pushScreen(new AppScreen());
    }

    /**
     * App entry point.
     * @param args Arguments.
     */
    public static void main(String[] args) {
        TestAppMain app = new TestAppMain();
        app.enterEventDispatcher();
    }

    /**
     * Main application screen.
     */
    private static class AppScreen extends MainScreen 
    {
        /**
         * Default constructor.
         */
        public AppScreen() {
            LabelField title = new LabelField("Button Test Demo",
                    LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
            setTitle(title);

            // Create a button with a field change listener.
            FieldChangeListener listener = new FieldChangeListener() {
                public void fieldChanged(Field field, int context) {
                    ButtonField buttonField = (ButtonField) field;
                    System.out.println("Button pressed: " + buttonField.getLabel());
                }
            };
            ButtonField buttonField = new ButtonField("Test Button", ButtonField.CONSUME_CLICK);            
            buttonField.setChangeListener(listener);
            add(buttonField);
        }               

        /**
         * Handle app closing.
         */
        public void close() {
            Dialog.alert("Goodbye!");
            System.exit(0);
            super.close();
        }
    }
}
十六岁半 2024-08-11 11:41:35

我同意 Fostah(+1) 的观点,在 Field、Manager 或 Screen 中实现 FieldChangeListener 是很常见的,或者使用独立的 FieldChangeListener。
另外,要从字段推/拉屏幕:

UiApplication.getUiApplication().pushScreen(nextScreen);

请参阅 如何导航回 Blackberry 模拟器中的上一个屏幕?

I agree with Fostah(+1), it's common to implement FieldChangeListener in Field, Manager or Screen, or use a standalone FieldChangeListener.
Also, to push/pull screen from Field:

UiApplication.getUiApplication().pushScreen(nextScreen);

See How to navigate back to the previous screen in the Blackberry emulator?

假面具 2024-08-11 11:41:35

我非常困惑,但我设法解决了问题。我从头开始创建了一个新类,然后将旧代码复制并粘贴到其中。一切正常。我唯一改变的只是导入 Eclipse 认为必要的类(在我从各种教程等中获得一些导入语句之前,所以有些可能没有被使用。)

我导入的东西是否有可能导致崩溃?

我真的宁愿将大部分代码放在屏幕本身中,但在我加载之前尝试这样做会导致整个事情崩溃。我对使用的 xml 解析器有些不满意。

http://pastie.org/621932

这是修改后的代码。我真的很沮丧,因为我知道对这个框架有一些固有的理解,而我并没有领悟到,我的大部分麻烦都来自于此。不过我想只有练习才能帮助我^_^;;

I'm super confused, but I managed to fix things. I created a new class from scratch, and then just copied and pasted my old code into it. Everything works. The only thing I changed was only importing classes that Eclipse said was necessary (before I had some import statements from various tutorials, etc. so some were possibly not being used.)

Is it possible I was importing something that was causing things to crash?

I really would rather have most of my code in the screen itself, but trying that crashes the whole thing before I can even load. Something about the xml parser I'm using not being happy.

http://pastie.org/621932

There's the modified code. I'm really frustrated, because I know that there is some inherent UNDERSTANDING of this frame work that I'm not grokking, and that most of my troubles are coming from this. I suppose only practice will help me, though ^_^;;

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