2017-10-16 58 views
0

我正在尝试使用javafx创建一个Gluon移动应用程序。我想创建一个登录页面,在成功登录的时候,我需要在点击按钮中加载另一个(第二视图)视图。我没有得到一个适当的例子。如果有人知道这一点,请帮助。我有两个视图主要演示者和辅助演示者(带FXML的胶子应用程序).​​Below是我的主要视图的控制器。如何在使用javafx的Gluon移动应用程序中切换视图?

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 
    } 
} 

}

回答

1

假设你正在使用的胶子插件 - 多视图项目,FXML模板,你可以很容易地MobileApplication.getInstance().switchView(viewName)切换视图。

你的情况:

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

如果您使用的是反光加力模板,而不是(也有用FXML),你可以使用类似:

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

你可以找到更多有关Gluon Mobile API here

+0

它工作正常。谢谢@Jose Pereda –

+0

好吧,考虑将答案标记为已接受(在左侧打勾),以便对其他人也有用。 –

相关问题