Blackberry Storm 9530 在滚动时跟踪触摸事件

发布于 2024-08-24 01:35:57 字数 1591 浏览 8 评论 0原文

嘿,在我的屏幕上有一个编辑字段和 2 个自定义按钮字段,分别为“确定”和“取消” 按钮字段下面有一些更多可聚焦的标签字段,

当我在编辑字段中写入名称并按 Enter 键时,

然后焦点将转到“确定”按钮,但如何将焦点设置在“取消​​”按钮上。此外,滚动时焦点不会自动向前移动???

我可能对触摸事件及其处理感到困惑该怎么办!

请大家帮帮忙!!!!!!!!!

代码:

        txt_Name = new EditField(TextField.NO_NEWLINE)
            {
                public void paint(net.rim.device.api.ui.Graphics g)
                {
                    g.setColor(Color.MAROON);
                    super.paint(g);
                }
           };

            txt_Name.setFont(font);

     v1 =  new VerticalFieldManager();
     v1.add(txt_Name );


    ButtonField btn1 = new ButtonField("OK",ButtonField.CONSUME_CLICK);
    ButtonField btn2 = new ButtonField("CANCEL",ButtonField.CONSUME_CLICK);

     v2 =  new VerticalFieldManager();
     v2.add(btn1);
     v2.add(btn2);

    LabelField l1 = new  LabelField("Hello Moon ",Field.Focussable);
    LabelField l2 = new  LabelField("Hello Citizen",Field.Focussable);
    LabelField l3 = new  LabelField("Hello People",Field.Focussable);
    LabelField l4 = new  LabelField("Hello world",Field.Focussable);

     v3 =  new VerticalFieldManager();
     v3.add(l1);
     v3.add(l2);
     v3.add(l3);
     v3.add(l4);

    add(v1);
    add(v2);
    add(v3);
}


protected boolean navigationClick(int status, int time) 
    {
     if(OK.isFocus())
             {
                //execute some code
                return true;
             }
if(CANCEL.isFocus())
             {
                //execute some code
                return true;
             }
        }

hey in my screen there is a an edit field and 2 custom button fields as "OK" and "CANCEL"
Below buttonfield there are some more focussable label fields

when i write a name in edit field and press enter then focus comes to "OK" button but how to set focus on "CANCEL" button.

Moreover while scrolling the focus does not automatically move ahead???

what to do may be i m confused with touch events and their handling!!!

Kindly help!!!!!!!!!!!!

Code:

        txt_Name = new EditField(TextField.NO_NEWLINE)
            {
                public void paint(net.rim.device.api.ui.Graphics g)
                {
                    g.setColor(Color.MAROON);
                    super.paint(g);
                }
           };

            txt_Name.setFont(font);

     v1 =  new VerticalFieldManager();
     v1.add(txt_Name );


    ButtonField btn1 = new ButtonField("OK",ButtonField.CONSUME_CLICK);
    ButtonField btn2 = new ButtonField("CANCEL",ButtonField.CONSUME_CLICK);

     v2 =  new VerticalFieldManager();
     v2.add(btn1);
     v2.add(btn2);

    LabelField l1 = new  LabelField("Hello Moon ",Field.Focussable);
    LabelField l2 = new  LabelField("Hello Citizen",Field.Focussable);
    LabelField l3 = new  LabelField("Hello People",Field.Focussable);
    LabelField l4 = new  LabelField("Hello world",Field.Focussable);

     v3 =  new VerticalFieldManager();
     v3.add(l1);
     v3.add(l2);
     v3.add(l3);
     v3.add(l4);

    add(v1);
    add(v2);
    add(v3);
}


protected boolean navigationClick(int status, int time) 
    {
     if(OK.isFocus())
             {
                //execute some code
                return true;
             }
if(CANCEL.isFocus())
             {
                //execute some code
                return true;
             }
        }

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

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

发布评论

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

评论(3

各自安好 2024-08-31 01:35:57

我按照马克的建议,为每个按钮单独设置 FieldChangeListener:

class Scr extends MainScreen {
    EditField txt_Name;
    ButtonField btnOK;
    ButtonField btnCancel;
    VerticalFieldManager v1;
    VerticalFieldManager v2;
    VerticalFieldManager v3;
    Font font = Font.getDefault().derive(Font.BOLD, 20);

    public Scr() {
        txt_Name = new EditField(TextField.NO_NEWLINE) {
            public void paint(net.rim.device.api.ui.Graphics g) {
                g.setColor(Color.MAROON);
                super.paint(g);
            }
        };

        txt_Name.setFont(font);

        v1 = new VerticalFieldManager();
        v1.add(txt_Name);

        btnOK = new ButtonField("OK", ButtonField.CONSUME_CLICK);
        btnOK.setChangeListener(
            new FieldChangeListener(){
                public void fieldChanged(Field field, int context) {
            Dialog.inform("OK pressed");
        }});
        btnCancel = new ButtonField("Cancel", ButtonField.CONSUME_CLICK);
        btnCancel.setChangeListener(
            new FieldChangeListener(){
                public void fieldChanged(Field field, int context) {
            Dialog.inform("Cancel pressed");
        }});
        v2 = new VerticalFieldManager();
        v2.add(btnOK);
        v2.add(btnCancel);

        LabelField l1 = new LabelField("Hello Moon", Field.FOCUSABLE);
        LabelField l2 = new LabelField("Hello Citizen", Field.FOCUSABLE);
        LabelField l3 = new LabelField("Hello People", Field.FOCUSABLE);
        LabelField l4 = new LabelField("Hello world", Field.FOCUSABLE);

        v3 = new VerticalFieldManager();
        v3.add(l1);
        v3.add(l2);
        v3.add(l3);
        v3.add(l4);

        add(v1);
        add(v2);
        add(v3);
    }
}

现在看起来没问题了:
替代文本 http://img40.imageshack.us/img40/6472/textentered.jpg< /a> 替代文本 http://img59.imageshack.us/img59/7574/okpressed .jpg 替代文本 http://img641.imageshack.us/img641/ 9246/cancelpressed01.jpg

更新

Swati 我可以使用 Storm 模拟器使用鼠标单击来单击这些按钮。
除了模拟器中的 cod 文件来自旧版本之外,我找不到任何其他解释。您可以通过更改代码中的任何标签文本来快速检查它,然后部署并检查此更改是否会应用到设备上的应用程序中。如果没有,这是旧版本,您应该清理模拟器并再次部署应用程序。
希望这对您有帮助!
另请参阅BlackBerry - 更改未反映在我的应用程序中

I made just like Mark suggested, separate FieldChangeListeners for each button:

class Scr extends MainScreen {
    EditField txt_Name;
    ButtonField btnOK;
    ButtonField btnCancel;
    VerticalFieldManager v1;
    VerticalFieldManager v2;
    VerticalFieldManager v3;
    Font font = Font.getDefault().derive(Font.BOLD, 20);

    public Scr() {
        txt_Name = new EditField(TextField.NO_NEWLINE) {
            public void paint(net.rim.device.api.ui.Graphics g) {
                g.setColor(Color.MAROON);
                super.paint(g);
            }
        };

        txt_Name.setFont(font);

        v1 = new VerticalFieldManager();
        v1.add(txt_Name);

        btnOK = new ButtonField("OK", ButtonField.CONSUME_CLICK);
        btnOK.setChangeListener(
            new FieldChangeListener(){
                public void fieldChanged(Field field, int context) {
            Dialog.inform("OK pressed");
        }});
        btnCancel = new ButtonField("Cancel", ButtonField.CONSUME_CLICK);
        btnCancel.setChangeListener(
            new FieldChangeListener(){
                public void fieldChanged(Field field, int context) {
            Dialog.inform("Cancel pressed");
        }});
        v2 = new VerticalFieldManager();
        v2.add(btnOK);
        v2.add(btnCancel);

        LabelField l1 = new LabelField("Hello Moon", Field.FOCUSABLE);
        LabelField l2 = new LabelField("Hello Citizen", Field.FOCUSABLE);
        LabelField l3 = new LabelField("Hello People", Field.FOCUSABLE);
        LabelField l4 = new LabelField("Hello world", Field.FOCUSABLE);

        v3 = new VerticalFieldManager();
        v3.add(l1);
        v3.add(l2);
        v3.add(l3);
        v3.add(l4);

        add(v1);
        add(v2);
        add(v3);
    }
}

Now it seems to be OK:
alt text http://img40.imageshack.us/img40/6472/textentered.jpg alt text http://img59.imageshack.us/img59/7574/okpressed.jpg alt text http://img641.imageshack.us/img641/9246/cancelpressed01.jpg

UPDATE

Swati I can click those buttons with Storm simulator using a mouse click.
I can't find any other explanation than cod file in simulator is from old version. You can check it quickly by changing any label text in code and then deploy and check if this change will be applied in app on device. In case if not, this is the old version and you should clean simulator and deploy app once again.
Hope this will help you!
See also BlackBerry - Changes are not getting reflected in my app

说不完的你爱 2024-08-31 01:35:57
    txt_Name = new EditField(TextField.NO_NEWLINE)
            {
                public void paint(net.rim.device.api.ui.Graphics g)
                {
                    g.setColor(Color.MAROON);
                    super.paint(g);
                }
           };

            txt_Name.setFont(font);

     v1 =  new VerticalFieldManager();
     v1.add(txt_Name );


    ButtonField btn1 = new ButtonField("OK",ButtonField.CONSUME_CLICK);
    ButtonField btn2 = new ButtonField("CANCEL",ButtonField.CONSUME_CLICK);

     h2 =  new HorizontalalFieldManager();
     h2.add(btn1);
     h2.add(btn2);

    LabelField l1 = new  LabelField("Hello Moon ",Field.Focussable);
    LabelField l2 = new  LabelField("Hello Citizen",Field.Focussable);
    LabelField l3 = new  LabelField("Hello People",Field.Focussable);
    LabelField l4 = new  LabelField("Hello world",Field.Focussable);

     v3 =  new VerticalFieldManager();
     v3.add(l1);
     v3.add(l2);
     v3.add(l3);
     v3.add(l4);

    add(v1);
    add(h2);
    add(v3);
}


protected boolean navigationClick(int status, int time) 
    {
int index = h2.getFieldwithFocusIndex();
     if(h2==0)
             {
                //execute some code for OK
                return true;
             }
if(h2==1)
             {
                //execute some code for cancel
                return true;
             }
        }
    txt_Name = new EditField(TextField.NO_NEWLINE)
            {
                public void paint(net.rim.device.api.ui.Graphics g)
                {
                    g.setColor(Color.MAROON);
                    super.paint(g);
                }
           };

            txt_Name.setFont(font);

     v1 =  new VerticalFieldManager();
     v1.add(txt_Name );


    ButtonField btn1 = new ButtonField("OK",ButtonField.CONSUME_CLICK);
    ButtonField btn2 = new ButtonField("CANCEL",ButtonField.CONSUME_CLICK);

     h2 =  new HorizontalalFieldManager();
     h2.add(btn1);
     h2.add(btn2);

    LabelField l1 = new  LabelField("Hello Moon ",Field.Focussable);
    LabelField l2 = new  LabelField("Hello Citizen",Field.Focussable);
    LabelField l3 = new  LabelField("Hello People",Field.Focussable);
    LabelField l4 = new  LabelField("Hello world",Field.Focussable);

     v3 =  new VerticalFieldManager();
     v3.add(l1);
     v3.add(l2);
     v3.add(l3);
     v3.add(l4);

    add(v1);
    add(h2);
    add(v3);
}


protected boolean navigationClick(int status, int time) 
    {
int index = h2.getFieldwithFocusIndex();
     if(h2==0)
             {
                //execute some code for OK
                return true;
             }
if(h2==1)
             {
                //execute some code for cancel
                return true;
             }
        }
我的影子我的梦 2024-08-31 01:35:57

您可以通过覆盖包含可聚焦字段(例如“确定”和“取消”按钮)的屏幕或管理器上的“navigationMovement”方法来控制焦点顺序。只需评估传入该方法的参数,使用 Field.setFocus() 将焦点设置在所需字段上,然后返回 true。

至于焦点不随滚动而移动——这就是触摸屏 UI 的工作方式。仅当您触摸可聚焦字段时,焦点才会移动 - 因此,如果您在“轻弹”屏幕滚动时没有触摸任何可聚焦字段,则焦点不会改变。

You can control the focus order by overriding the "navigationMovement" method on the screen or manager containing the focusable fields, such as the okay and cancel buttons. Just evaluate the arguments passed in to that method, set focus on the desired field using Field.setFocus(), and return true.

As for the focus not moving ahead with scrolling - that's just the way the touchscreen UI works. The focus only moves when you touch a focusable field - so if you aren't touching any focusable fields when you "flick" the screen to scroll, the focus won't change.

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