0

I'm trying to use different type of enums in the same ListView.

I got interface for enums

public interface Item {
    int getId();
    String getName();
}

Then I create enum

public enum Items1 implements Item {
    Item1(1, "Item1"),
    Item2(2, "Item2");
    private int id;
    private String name;

    // Overridden getters from interface.
}

I have view with ListView.

class SimpleView {
    private ListView<Items1> items;

    public void initialize() {
        items.setItems(viewModel.getItems());
    }
}

This code works only with Items1 enums elements of course.

Then I create a second enum

public enum Items2 implements Item {
    TestItem(123, "TEST"),
    DevItem(321, "DEV");
    private int id;
    private String name;

    // Overridden getters from interface.
}

Is there any way to load depending on some condition elements from two different enums to the same ListView?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
p_som
  • 1
  • 1

1 Answers1

0

A custom ListCell should allow you to specify what should be displayed in each cell based on some condition. See https://www.turais.de/how-to-custom-listview-cell-in-javafx/ and JavaFX using a custom listcell for some direction.

samt
  • 11
  • 3