【问题标题】:How to switch views in Gluon mobile app using javafx?如何使用 javafx 在 Gluon 移动应用程序中切换视图?
【发布时间】:2017-10-16 09:12:20
【问题描述】:

我正在尝试使用 javafx 创建一个 Gluon 移动应用程序。我想创建一个登录页面,在成功登录时,我需要通过单击按钮加载另一个(第二视图)视图。我没有得到一个合适的例子。如果有人知道这一点,请提供帮助。我有两个视图主要演示者和次要演示者。(使用 FXML 的胶子应用程序)。下面是我的主要视图的控制器。

public class PrimaryPresenter {

@FXML
private View primary;

private Label label;
@FXML
private TextField username;
@FXML
private Button loginBt;

private Alert alert;
@FXML
private PasswordField password;
public void initialize() {
    primary.showingProperty().addListener((obs, oldValue, newValue) -> {
        if (newValue) {
            AppBar appBar = MobileApplication.getInstance().getAppBar();
            appBar.setNavIcon(MaterialDesignIcon.MENU.button(e
                    -> MobileApplication.getInstance().showLayer(ArjunsApp.MENU_LAYER)));
            appBar.setTitleText("Primary");
            appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e
                    -> System.out.println("Search")));
        }
    });
}

@FXML
private void buttonClick(ActionEvent event) {
    if(username.getText().equals("")){
        alert = new Alert(AlertType.ERROR,"Enter username");
        alert.showAndWait();
    }else if(password.getText().equals("")){
        alert = new Alert(AlertType.ERROR,"Enter password");
        alert.showAndWait();
    }else{
        //Code to load my secondary view
    }
}

}

【问题讨论】:

    标签: java android javafx gluon-mobile


    【解决方案1】:

    假设您使用的是 Gluon 插件 - 带有 FXML 模板的多视图项目,您可以使用 MobileApplication.getInstance().switchView(viewName) 轻松切换视图。

    在你的情况下:

    @FXML
    private void buttonClick(ActionEvent event) {
        ...
        MobileApplication.getInstance().switchView("SECONDARY_VIEW");
    }
    

    如果您改用 Glisten-Afterburner 模板(它也使用 FXML),您可以使用类似:

    @FXML
    private void buttonClick(ActionEvent event) {
        ...
        AppViewManager.SECONDARY_VIEW.switchView();
    }
    

    您可以找到有关 Gluon 移动 API here 的更多信息。

    【讨论】:

    • 好的,考虑将答案标记为已接受(在左侧打勾),以便对其他人也有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多