Inhaltsstoffe in Filter Maske anzeigen

This commit is contained in:
Sven Alteköster 2024-01-23 14:58:19 +01:00
parent 450e08b8e7
commit c6b4bc1cd1
2 changed files with 32 additions and 2 deletions

View File

@ -9,4 +9,10 @@ public class Zutat {
public String getName(){
return this.name;
}
@Override
public String toString() {
return name;
}
}

View File

@ -7,14 +7,21 @@
package de.subway_surfers.vpr_app;
import Logik.Kind;
import Logik.Zutat;
import RestAPISchnittstelle.RestApiClient;
import com.google.gson.*;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import java.util.ArrayList;
public class InhaltsstoffeFilternController {
private @FXML ListView<zutatListViewController> zutatListView;
private @FXML ListView<Zutat> zutatListView;
private @FXML CheckBox speichernCheckBox;
@ -22,11 +29,28 @@ public class InhaltsstoffeFilternController {
private @FXML Button fortfahrenButton;
private ArrayList<Zutat> zutaten;
public void initialize(){
// hier ListView füllen
zutatListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
RestApiClient api = new RestApiClient();
String json = api.get("Inhaltsstoff");
zutaten = new ArrayList<>();
Gson gson = new Gson();
JsonElement je = JsonParser.parseString(json);
JsonArray ja = je.getAsJsonArray();
for (JsonElement e : ja) {
JsonObject jo = e.getAsJsonObject();
zutaten.add(gson.fromJson(jo, Zutat.class));
}
zutatListView.setItems(FXCollections.observableArrayList(zutaten));
}
}