2

I've got MAIN (controller) where is 1)List of questions. From that MAIN view I start second view, where I want to see 1)List of my question and from that view I want add question to 1)List in MAIN controller. Is possible to transfer data between controller (update data in first controller from second, and see list of data from first in second)?

Maybe it's simple question, but I can't do that.

Mathew
  • 71
  • 5
  • Passing a `ObservableList` to the controller should do the trick : https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml If the `Question` type is not immutable, you probably need to design it properly & make sure the right listeners/bindings in the main view are in place... – fabian Sep 30 '19 at 16:37

1 Answers1

0

I suggest this example code, this shows how to update List from View. It's basics can be upgraded to ActionListeners and Observable Objects as needed, I guess.

public class Main {

    private static List<Integer> list;
    private static View view;

    public static void main(String[] args) {
        list = new ArrayList<>();
        view = new View();
        view.setList(list);

        view.updateList(5);

        System.out.println(list);
    }

    public List<Integer> getList() {
        return list;
    }

    public void setList(List<Integer> list) {
        this.list = list;
    }
}


public class View {

    private List<Integer> list;

    public void updateList(Integer i) {
        list.add(i);
    }

    public List<Integer> getList() {
        return list;
    }

    public void setList(List<Integer> list) {
        this.list = list;
    }
}
user0856
  • 3
  • 1
  • 4