[英]Update text in a ListView
I am trying update the text of an index
in my ListView
when text is typed into a TextField
, but I don't know how to access the item to update the text. 当我在
TextField
键入文本时,我正在尝试在ListView
更新index
文本,但是我不知道如何访问该项目以更新文本。 I know the index
of the item, but I just cant seem to figure out how to update the text.. 我知道该项目的
index
,但是我似乎无法弄清楚如何更新文本。
@FXML
ListView connections;
public ObservableList names = FXCollections.observableArrayList();
@FXML
public void onInputChanged(KeyEvent event){
TextField fld = (TextField) event.getTarget();
if(fld.getId().equals("txtName") && index > -1){
}
}
names.set(index, fld.getText());
I think you need to use JavaFX Properties ie "SimpleStringProperty" to actually change the String in "names". 我认为您需要使用JavaFX属性(即“ SimpleStringProperty”)来实际更改“名称”中的字符串。
This link does explain it pretty accurately: https://gist.github.com/andytill/3116827 该链接确实非常准确地解释了它: https : //gist.github.com/andytill/3116827
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.