2012-12-17 49 views
0

我試圖創建自己的複合鍵,使用DIV作爲外父:將元素投射到FlowPanel?

public class CompoundButton extends ButtonBase { 
    public CompoundButton() { 
     super(DOM.createDiv()); 
    } 
} 

ButtonBase的構造希望有一個元素實例,雖然,所以我使用的DOM.createDiv()呼叫。但我怎麼能在這一點?:

public CompoundButton() { 
    super(DOM.createDiv()); <-- we're just a div. 

    // ButtonBase has no "add()" method - but this class is really 
    // just a div instance, so shouldn't I be able to convert it to 
    // a FlowPanel for example to be able to add elements to it here? 
    this.add(new FlowPanel()); <-- not possible, "add()" not available here. 

感謝

+1

您只需使用一個標籤或FlowPanel和風格它看起來像一個按鈕。你需要從ButtonBase中獲得什麼? –

+0

我需要爲它添加移動設備的事件處理程序。正常的addClickHandler實現在移動瀏覽器上無法正常工作,因爲內置了300毫秒的點擊延遲。 – user291701

+2

哪些處理程序? Label幾乎與ButtonBase具有相同的處理程序,包括HasAllTouchHandlers和HasAllGestureHandlers。 –

回答

0

按鈕底座採用一個單元格,flowpanel不是細胞和你的複合按鈕的代碼是錯誤的,因爲它不發送添加子部件現在一個細胞到它的父母。

正確的代碼是

public class CompoundButton<C> extends ButtonBase<C> 
{ 
    protected CompoundButton(ButtonCellBase<C> cell) 
    { 
     super(cell); 
    } 
}