我正在尝试制作ListView
可编辑,但当我在代码中添加事件处理程序onEditCommit
和onEditCancel
时,我无法更改ListView
中的文字。在我的代码下面(执行但编辑不起作用):
public class ItensTipoStringController implements Initializable {
@FXML
private ListView lstItens;
ArrayList<String> itens = new ArrayList<>();
ObservableList itensObservaveis = FXCollections.observableArrayList(itens);
@Override
public void initialize(URL url, ResourceBundle rb) {
itens.add("Evandro");
itens.add("Miguel");
lstItens.setEditable(true);
lstItens.setCellFactory(TextFieldListCell.forListView());
lstItens.getItems().addAll(itens);
lstItens.setOnEditCommit(new EventHandler() {
@Override
public void handle(Event event) {
System.out.println("onEditCommit");
}
});
lstItens.setOnEditCancel(new EventHandler() {
@Override
public void handle(Event event) {
System.out.println("onEditCancel");
}
});
lstItens.setOnEditStart(new EventHandler() {
@Override
public void handle(Event event) {
System.out.println("onEditStart");
}
});
}
}