如何使用javafx在Gluon移动应用程序中切换视图



我正在尝试使用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
    }
}

}

假设您使用的是带有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 Mobile API的更多信息。

相关内容

最新更新