我想做一個視圖類,提供一個水平或垂直佈局取決於它是如何創建的。我正在使用委託來實現此目的。黑莓 - 樂趣與FieldManagers
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
}
當我實例化一個View對象時,我傳入一個水平或垂直字段管理器,然後委託調用。這是Screen類在黑莓中所做的。
其實我在看黑莓文檔的屏幕上看到什麼叫它代表(所以我可以模仿)和我注意到像這樣在視屏通話...
保護布爾keyChar(焦ç ,int狀態,int time)
將密鑰生成事件委派給焦點受控字段。 此方法在此屏幕的代理管理器上調用Manager.keyChar(char,int,int)。
那麼它馬上就會對我產生影響,他們如何在屏幕的代表上調用受保護的方法?或者是文檔錯誤,這種方法沒有被委託?
任何人都知道他們是如何完成的?