Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 黑莓-现场经理的乐趣_User Interface_Blackberry_Layout - Fatal编程技术网

User interface 黑莓-现场经理的乐趣

User interface 黑莓-现场经理的乐趣,user-interface,blackberry,layout,User Interface,Blackberry,Layout,我试图创建一个视图类,它根据创建方式提供水平或垂直布局。我正在使用一个代理来实现这一点 class View extends Manager { private Manager mDelegate; public View(Manager inDelegate) { mDelegate = inDelegate; // the delegate is the only child of "this" manager.

我试图创建一个视图类,它根据创建方式提供水平或垂直布局。我正在使用一个代理来实现这一点

class View extends Manager {
    private Manager mDelegate;

    public View(Manager inDelegate) {
        mDelegate = inDelegate;
        // the delegate is the only child of "this" manager.
        super.add(mDelegate);
    }

    public void add(Field f) {
        // all other children go into the delegate.    
        mDelegate.add(f);
    }

    // other methods that also delegate

}
当我实例化一个视图对象时,我传入一个水平或垂直字段管理器,然后将调用委托给该管理器。这就是Screen类在blackberry中所做的

事实上,我正在查看blackberry docs for Screen,以查看它是如何调用委托的(因此我可以进行模拟),我注意到屏幕上出现了类似这样的调用

受保护的布尔键字符(字符c、整型状态、整型时间)

将密钥生成事件委托给具有焦点的受控字段。 此方法在此屏幕的委托管理器上调用Manager.keyChar(char,int,int)

于是我立刻意识到,他们究竟是如何在屏幕的委托上调用受保护的方法的?或者是单据有误,且该方法未授权

有人知道他们是如何做到这一点的吗?

提醒自己:

受保护的方法可以由调用 类中的任何子类,但不是 不相关的班级

这并不能直接回答您的问题,但是您是否可以扩展
屏幕
()而不是
管理器
,然后在构造函数中调用
super(mDelegate)
?那么想必任何必要的魔法都会奏效

除此之外,我建议您尝试一下,看看是否可以覆盖假定受保护的方法

提醒自己:

受保护的方法可以由调用 类中的任何子类,但不是 不相关的班级

这并不能直接回答您的问题,但是您是否可以扩展
屏幕
()而不是
管理器
,然后在构造函数中调用
super(mDelegate)
?那么想必任何必要的魔法都会奏效


除此之外,我建议您尝试一下,看看是否可以覆盖假定受保护的方法

在其他一些问题的帮助下,我设法找到了这个问题的解决方案

我的解决方案是创建一个接口,为受保护的方法提供公共访问点,然后对Manager类进行子类化,并在该接口中混合使用。然后,public方法将调用其super的protected方法

然后将视图类传递给这些管理器子类之一

public interface ManagerDelegate {
    Manager asManager();
    // Provide public access points to any protected methods needed.
    void doProtectedMethod();
}

public HorizontalDelegate extends HorizontalFieldManager implements ManagerDelegate {
    public Manager asManager() {
        return this;
    }
    public void doProtectedMethod() {
        // call the Manager's protected method.
        protectedMethod();
    }
}

public VerticalDelegate extends VerticalFieldManager implements ManagerDelegate {
    public Manager asManager() {
        return this;
    }
    public void doProtectedMethod() {
        // call the Manager's protected method.
        protectedMethod();
    }
}

public class View extends Manager {
    private final ManagerDelegate mDelegate;

    public View(ManagerDelegate inDelegate) {
        mDelegate = inDelegate;
    }

    protected void protectedMethod() {
        // Call into our delegate's public method to access its protected method.
        mDelegate.doProtectedMethod();
    }

    public void publicMethod() {
        // For public delegated methods I can just get the Manager instance from
        // the delegate and call directly.
        mDelegate.asManager().publicMethod();
    }
}

在其他一些问题的帮助下,我设法找到了解决这个问题的办法

我的解决方案是创建一个接口,为受保护的方法提供公共访问点,然后对Manager类进行子类化,并在该接口中混合使用。然后,public方法将调用其super的protected方法

然后将视图类传递给这些管理器子类之一

public interface ManagerDelegate {
    Manager asManager();
    // Provide public access points to any protected methods needed.
    void doProtectedMethod();
}

public HorizontalDelegate extends HorizontalFieldManager implements ManagerDelegate {
    public Manager asManager() {
        return this;
    }
    public void doProtectedMethod() {
        // call the Manager's protected method.
        protectedMethod();
    }
}

public VerticalDelegate extends VerticalFieldManager implements ManagerDelegate {
    public Manager asManager() {
        return this;
    }
    public void doProtectedMethod() {
        // call the Manager's protected method.
        protectedMethod();
    }
}

public class View extends Manager {
    private final ManagerDelegate mDelegate;

    public View(ManagerDelegate inDelegate) {
        mDelegate = inDelegate;
    }

    protected void protectedMethod() {
        // Call into our delegate's public method to access its protected method.
        mDelegate.doProtectedMethod();
    }

    public void publicMethod() {
        // For public delegated methods I can just get the Manager instance from
        // the delegate and call directly.
        mDelegate.asManager().publicMethod();
    }
}