黑莓:如果另一个字段绘制到相同的 x 坐标,则获得字段焦点时出现问题

发布于 2024-11-08 12:13:52 字数 2508 浏览 0 评论 0原文

我有一个 AbsoluteFieldManager,其中包含水平行中的多个字段,切换焦点效果很好。现在我需要在与上面左侧字段相同的水平位置上添加另一个字段。这样做时,我无法再专注于第一个字段。屏幕应如下所示:

________________________
|  ____   ____   ____  |
| |_f1_| |_f2_| |_f3_| |
|  ____                |
| |_f4_|               | with f4 added here, f1 isn't focusable, once it has
|______________________| lost focus.

如果您有任何解决此问题的想法,我将不胜感激。这是到目前为止我的代码:

TestScreen:

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.container.AbsoluteFieldManager;
import net.rim.device.api.ui.container.MainScreen;

public class TestScreen extends MainScreen {
    int screenY = Display.getWidth();
    int screenX = Display.getHeight();

    public TestScreen() {
        AbsoluteFieldManager manager = new AbsoluteFieldManager();
        TestField f1 = new TestField(50, 50, true);
        TestField f2 = new TestField(50, 50, true);
        TestField f3 = new TestField(50, 50, true);
        TestField f4 = new TestField(50, 50, true);
        TestField f5 = new TestField(50, 50, false);
        manager.add(f1, 0, 0);
        manager.add(f2, 60, 0);
        manager.add(f3, 120, 0);
        manager.add(f4, 180, 0);
        // this works fine: 
        // manager.add(f5, 1, 80);
        // this not:
        manager.add(f5, 0, 80);
        add(manager);
    }
}

TestField:

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;


public class TestField extends Field {
    boolean isFocusable;
    int width, height;
    int bgColorUnfocused, bgColorFocused;
    public TestField(int width, int height, boolean isFocusable){
        this.width=width;
        this.height=height;
        this.isFocusable=isFocusable;
        bgColorUnfocused= 0xC0C0C0;
        bgColorFocused = 0x3956F7;
    }
    protected void layout(int w, int h) {
        setExtent(width, height);
    }
    public boolean isFocusable() {
        return isFocusable;
    }
    protected void paint(Graphics g) {
        g.setColor(isFocus() ? bgColorFocused : bgColorUnfocused);
        g.fillRect(0, 0, width, height);        
    }

}

TestApp:

import net.rim.device.api.ui.UiApplication;


public class TestApp extends UiApplication{
    TestScreen screen = new TestScreen();
    public static void main(String args[]){
        TestApp app = new TestApp();
        app.enterEventDispatcher();
    }
    public TestApp(){
        pushScreen(screen);
    }
}

I have an AbsoluteFieldManager that contains several Fields in a horizontal row, switching the focus works fine. Now i need to add another Field on the same horizontal position as the left field above. When doing so, I can no more focus the first field. The screen should look as this:

________________________
|  ____   ____   ____  |
| |_f1_| |_f2_| |_f3_| |
|  ____                |
| |_f4_|               | with f4 added here, f1 isn't focusable, once it has
|______________________| lost focus.

If you got any Ideas how to fix this, I'd apreciate. Here is my Code so far:

TestScreen:

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.container.AbsoluteFieldManager;
import net.rim.device.api.ui.container.MainScreen;

public class TestScreen extends MainScreen {
    int screenY = Display.getWidth();
    int screenX = Display.getHeight();

    public TestScreen() {
        AbsoluteFieldManager manager = new AbsoluteFieldManager();
        TestField f1 = new TestField(50, 50, true);
        TestField f2 = new TestField(50, 50, true);
        TestField f3 = new TestField(50, 50, true);
        TestField f4 = new TestField(50, 50, true);
        TestField f5 = new TestField(50, 50, false);
        manager.add(f1, 0, 0);
        manager.add(f2, 60, 0);
        manager.add(f3, 120, 0);
        manager.add(f4, 180, 0);
        // this works fine: 
        // manager.add(f5, 1, 80);
        // this not:
        manager.add(f5, 0, 80);
        add(manager);
    }
}

TestField:

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;


public class TestField extends Field {
    boolean isFocusable;
    int width, height;
    int bgColorUnfocused, bgColorFocused;
    public TestField(int width, int height, boolean isFocusable){
        this.width=width;
        this.height=height;
        this.isFocusable=isFocusable;
        bgColorUnfocused= 0xC0C0C0;
        bgColorFocused = 0x3956F7;
    }
    protected void layout(int w, int h) {
        setExtent(width, height);
    }
    public boolean isFocusable() {
        return isFocusable;
    }
    protected void paint(Graphics g) {
        g.setColor(isFocus() ? bgColorFocused : bgColorUnfocused);
        g.fillRect(0, 0, width, height);        
    }

}

TestApp:

import net.rim.device.api.ui.UiApplication;


public class TestApp extends UiApplication{
    TestScreen screen = new TestScreen();
    public static void main(String args[]){
        TestApp app = new TestApp();
        app.enterEventDispatcher();
    }
    public TestApp(){
        pushScreen(screen);
    }
}

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

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

发布评论

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

评论(1

快乐很简单 2024-11-15 12:13:52

由于 AbsoluteFieldManager 不确定您将项目放置在哪里,因此它不知道使用拨轮时发送焦点的顺序。如果您想对此进行管理,请调用 AFM 的 nextFocus(int, int) ,以便您可以根据焦点位置和预期移动位置来指定谁获得焦点。

看一下 http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/Manager.html#nextFocus(int,%20int) 了解更多详细信息。

Since AbsoluteFieldManager isn't really sure where you're placing items, it doesn't know what order to send focus when using the trackwheel. If you want to manage this, ovveride nextFocus(int, int) of the AFM so you can specify who gets the focus based off of where it is and where the intended movement is.

Take a look at http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/Manager.html#nextFocus(int,%20int) for more details.

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