1 回答

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊
updateItem可以調(diào)用任意次數(shù),可以傳遞不同的項(xiàng)目,單元格可以從空變?yōu)榉强?,反之亦然。ListView創(chuàng)建與您在屏幕上看到的一樣多的單元格,并用項(xiàng)目填充它們。例如,滾動(dòng)或修改列表items或調(diào)整大小ListView可以導(dǎo)致更新。
出于這個(gè)原因,任何單元格都需要能夠處理傳遞null給該方法的任意項(xiàng)目序列(或+空)updateItem。
此外,您應(yīng)該避免調(diào)用setItem自己,因?yàn)閟uper.updateItem已經(jīng)這樣做了。setGraphic如果要在單元格中顯示項(xiàng)目,請(qǐng)改用:
@Override
public ListCell<TextFlow> call(ListView<TextFlow> param) {
return new ListCell<TextFlow>() {
@Override
protected void updateItem(TextFlow item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setStyle("-fx-control-inner-background: blue;");
setGraphic(item);
} else {
setStyle(null);
setGraphic(null);
System.out.println("Item is null.");
}
}
};
}
添加回答
舉報(bào)