首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未在mgwt中触发的分路事件

未在mgwt中触发的分路事件
EN

Stack Overflow用户
提问于 2013-01-15 17:46:34
回答 1查看 948关注 0票数 1

我刚刚开始学习mgwt。创建Button并添加TapHandler后,不会触发tap事件。我不知道代码中出了什么问题。我已经将其部署在GAE上,并在Android设备上访问该站点。以下是onModuleLoad()的代码

代码语言:javascript
复制
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);
    }
}

有人能帮我解决这个问题吗?谢谢..!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-16 17:51:17

您正在向一个区域添加多个AnimatableDisplays。这些将会重叠。

我想您只是在mgwt showcase中添加了几行代码,而没有删除showcase代码。要解决这个问题,您可以从计时器中删除对start()的调用。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14334920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档