2011-01-20 251 views
0

我想添加一個處理程序,在gwt切換按鈕顯示下面時繼續執行。我正在嘗試keydown,但這不起作用。切換按鈕中是否有任何方法允許此?GWT切換按鈕

回答

0

使用Timer

ToggleButton myToggle = new ToggleButton(); 

Timer myTimer = new Timer() { 
    @Override 
    public void run() { 
    if (myToggle.isDown()) { 
     // Perform repeating action. 
    } else { 
     cancel(); 
    } 
    } 
}; 

myToggle.addValueChangeHandler(new ValueChangeHandler<Boolean>() { 
    @Override 
    public void onValueChange(ValueChangeEvent<Boolean> event) { 
    if (event.getValue().booleanValue() == true) { 
     // Perform the repeating action twice/second. 
     myTimer.scheduleRepeating(500); 
    } 
    } 
});