我刚开始学习mgwt。创建Button
并添加TapHandler
后,不会触发点击事件。我不知道代码中有什么问题。我已经在GAE上部署了这个并在Android设备上访问该站点。以下是onModuleLoad()
import com.citrix.demo.client.css.AppBundle;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.dom.client.StyleInjector;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.mvp.client.AnimatableDisplay;
import com.googlecode.mgwt.mvp.client.AnimatingActivityManager;
import com.googlecode.mgwt.mvp.client.Animation;
import com.googlecode.mgwt.mvp.client.AnimationMapper;
import com.googlecode.mgwt.ui.client.MGWT;
import com.googlecode.mgwt.ui.client.MGWTSettings;
import com.googlecode.mgwt.ui.client.MGWTStyle;
import com.googlecode.mgwt.ui.client.animation.AnimationHelper;
import com.googlecode.mgwt.ui.client.dialog.TabletPortraitOverlay;
import com.googlecode.mgwt.ui.client.layout.MasterRegionHandler;
import com.googlecode.mgwt.ui.client.layout.OrientationRegionHandler;
import com.googlecode.mgwt.ui.client.widget.Button;
import com.googlecode.mgwt.ui.client.widget.LayoutPanel;
/**
* @author Daniel Kurka
*
*/
public class MgwtAppEntryPoint implements EntryPoint {
private static LayoutPanel layout = new LayoutPanel();
private void start() {
//set viewport and other settings for mobile
MGWT.applySettings(MGWTSettings.getAppSetting());
final ClientFactory clientFactory = new ClientFactoryImpl();
// Start PlaceHistoryHandler with our PlaceHistoryMapper
AppPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);
final PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
historyHandler.register(clientFactory.getPlaceController(), clientFactory.getEventBus(), new com.citrix.demo.client.activities.HomePlace());
if ((MGWT.getOsDetection().isTablet())) {
// very nasty workaround because GWT does not correctly support
// @media
StyleInjector.inject(AppBundle.INSTANCE.css().getText());
createTabletDisplay(clientFactory);
} else {
createPhoneDisplay(clientFactory);
}
historyHandler.handleCurrentHistory();
}
private void createPhoneDisplay(ClientFactory clientFactory) {
AnimatableDisplay display = GWT.create(AnimatableDisplay.class);
PhoneActivityMapper appActivityMapper = new PhoneActivityMapper(clientFactory);
PhoneAnimationMapper appAnimationMapper = new PhoneAnimationMapper();
AnimatingActivityManager activityManager = new AnimatingActivityManager(appActivityMapper, appAnimationMapper, clientFactory.getEventBus());
activityManager.setDisplay(display);
RootPanel.get().add(display);
}
private void createTabletDisplay(ClientFactory clientFactory) {
SimplePanel navContainer = new SimplePanel();
navContainer.getElement().setId("nav");
navContainer.getElement().addClassName("landscapeonly");
AnimatableDisplay navDisplay = GWT.create(AnimatableDisplay.class);
final TabletPortraitOverlay tabletPortraitOverlay = new TabletPortraitOverlay();
new OrientationRegionHandler(navContainer, tabletPortraitOverlay, navDisplay);
new MasterRegionHandler(clientFactory.getEventBus(), "nav", tabletPortraitOverlay);
ActivityMapper navActivityMapper = new TabletNavActivityMapper(clientFactory);
AnimationMapper navAnimationMapper = new TabletNavAnimationMapper();
AnimatingActivityManager navActivityManager = new AnimatingActivityManager(navActivityMapper, navAnimationMapper, clientFactory.getEventBus());
navActivityManager.setDisplay(navDisplay);
RootPanel.get().add(navContainer);
SimplePanel mainContainer = new SimplePanel();
mainContainer.getElement().setId("main");
AnimatableDisplay mainDisplay = GWT.create(AnimatableDisplay.class);
TabletMainActivityMapper tabletMainActivityMapper = new TabletMainActivityMapper(clientFactory);
AnimationMapper tabletMainAnimationMapper = new TabletMainAnimationMapper();
AnimatingActivityManager mainActivityManager = new AnimatingActivityManager(tabletMainActivityMapper, tabletMainAnimationMapper, clientFactory.getEventBus());
mainActivityManager.setDisplay(mainDisplay);
mainContainer.setWidget(mainDisplay);
RootPanel.get().add(mainContainer);
}
@Override
public void onModuleLoad() {
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void onUncaughtException(Throwable e) {
Window.alert("uncaught: " + e.getMessage());
e.printStackTrace();
}
});
new Timer() {
@Override
public void run() {
start();
}
}.schedule(1);
//set viewport and other settings for mobile
MGWT.applySettings(MGWTSettings.getAppSetting());
MGWTStyle.getTheme().getMGWTClientBundle().getMainCss().ensureInjected();
Label label = new Label("Welcome");
label.setAutoHorizontalAlignment(Label.ALIGN_CENTER);
Button button = new Button();
button.setRound(true);
button.setText("Click");
button.addTapHandler(new TapHandler() {
@Override
public void onTap(TapEvent event) {
Window.alert("Hola !");
}
});
layout.add(label);
layout.add(button);
//build animation helper and attach it
AnimationHelper animationHelper = new AnimationHelper();
// RootPanel.get().add(layout);
RootPanel.get().add(animationHelper);
animationHelper.goTo(layout, Animation.POP);
}
}
有人可以帮我解决这个问题吗?谢谢..!
答案 0 :(得分:2)
您正在向一个区域添加多个AnimatableDisplays。那些将重叠。
你刚刚在mgwt展示中添加了一些代码行,我想在不删除展示代码的情况下。要解决此问题,您可以从计时器中删除对start()的调用。