如何将TableView项目绑定到正在运行的服务值(如ListView中):

todoList.itemsProperty().bind(service.valueProperty());


当我尝试时,出现编译时错误:

error: method bind in interface Property<T> cannot be applied to given types:
required : ObservableValue<? extends ObservableList<TodoTAsk>>
found : ReadOnlyObjectProperty<List<TodoTask>>


编辑:我的服务班级

public final class AllTasks extends Service<ObservableList<TodoTask>> {
    @Override
    protected Task<ObservableList<TodoTask>> createTask() {
       return new Task<ObservableList<TodoTask>>() {
          @Override
          protected ObservableList<TodoTask> call() throws Exception {
          ObservableList<TodoTask> list =      FXCollections.observableArrayList();
         //    list.addAll(new TaskRepository().getAllTasks());
          for (TodoTask task : new TaskRepository().getAllTasks()) {
              Thread.sleep(1500);
          list.add(task);
          }
          System.out.println(list);
          return list;
        }
     };
   }
}

最佳答案

您如何定义服务?

尝试类似的东西:

public class MyService extends Service<ObservableList<TodoTAsk>>

10-08 14:39