João Ferreira
João Ferreira

Reputation: 55

What can I do to my ListView changes between two different data types?

Here's my listView:

public ListView<Consulta> lstViewLista;

Here I want my listView like it is (listView<Consulta>):

public void btnDireitaOnAction(ActionEvent event){
    ObservableList<Consulta> consultaData = FXCollections.observableArrayList();
    try {
        consultaData.addAll(ConsultaDAO.buscarPorData(Agenda.getData()));
    } catch (Exception e) {
        System.err.println("Erro: Impossível encontrar as consultas.");
        e.printStackTrace();
    }
    lstViewLista.setItems(consultaData);
}

But here I want my listView like listView<Paciente>:

public void btnDireitaOnAction(ActionEvent event){
ObservableList<Paciente> pacienteData = FXCollections.observableArrayList();
try {
    pacienteData.addAll(PacienteDAO.buscarPorData(Agenda.getData()));
} catch (Exception e) {
    System.err.println("Erro: Impossível encontrar os pacientes.");
    e.printStackTrace();
}
lstViewLista.setItems(pacienteData);

}

How can I change between them? Someone help T_T

Upvotes: 0

Views: 108

Answers (1)

MMAdams
MMAdams

Reputation: 1498

You define lstViewLista as being a ListView of type <Consulta>, so it's probably not wise to change it's type. Why not have two ListViews, one of type <Consulta> and one of type <Paciente>, like this?

ListView<Consulta> lstViewConsulta;
ListView<Paciente> lstViewPaciente;

You could switch which one is showing by either adding and removing it from it's parent node using Node.getChildren() or by using setManaged() and setVisible() like this:

//hide lstViewConsulta and show lstViewPaciente
lstViewConsulta.setVisible(false);
lstViewConsulta.setManaged(false);
lstViewPaciente.setVisible(true);
lstViewPaciente.setManaged(true);

Upvotes: 1

Related Questions