2017-10-16 163 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

好吧,考慮將答案標記爲已接受(在左側打勾),以便對其他人也有用。 –

相關問題