问题
I have a tab layout panel in my ui.xml :
<g:TabLayoutPanel ui:field="tabPanel" barHeight='30'>
<g:tab>
<g:header size='7'>tab1</g:header>
<g:SimplePanel ui:field="tab1" height="100%"/>
</g:tab>
<g:tab>
<g:header size='7'>tab2</g:header>
<g:SimplePanel ui:field="tab2" height="100%"/>
</g:tab>
</g:TabLayoutPanel>
how do I handle the event generated on clicking Tab2?
回答1:
Handle the SelectionEvent<Integer>
or BeforeSelectionEvent<Integer>
depending on your requirements.
e.g:
tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
@Override
public void onSelection(SelectionEvent<Integer> event) {
if (event.getSelectedItem() == 1) {
// Code
}
}
});
or:
@UiHandler("tabPanel")
void onTabSelection(SelectionEvent<Integer> event) {
if (event.getSelectedItem() == 1) {
// Code
}
}
来源:https://stackoverflow.com/questions/9059214/in-gwt-how-do-i-handle-the-tab-click-event