1
我想在ListView
中製作一個自定義單元格。請原諒我英語不好! 我想在ListView
中顯示圖片,名稱和狀態。 對此,我使用不同的Fxml
,其中包含Hbox
。如何使用ListView中的自定義單元格下載fxml?
public class Controller {
CollectionContactForListCollection contactForList = new CollectionContactForListCollection();
@FXML
private ListView<Contact> listContact ;
@FXML
HBox hbox;
@FXML
ImageView avatar;
@FXML
Label labelName;
@FXML
Label lblStatus;
@FXML
Label lblSense;
@FXML
private void initialize(){
contactForList.fieldData();
// listContact.setItems((ObservableList) contactForList.getContactList());
listContact.setCellFactory(new Callback<ListView<Contact>, ListCell<Contact>>() {
@Override
public ListCell<Contact> call(ListView<Contact> param) {
ListCell<Contact> listCell = new ListCell<Contact>() {
@Override
protected void updateItem(Contact item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
//This method does not work download
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/boxInContact.fxml"));
fxmlLoader.setController(this);
labelName.setText(item.getName());
lblSense.setText(item.getSense());
lblStatus.setText(item.getStatus());
avatar.setImage(item.getImage());
}
}
};
return listCell;
}
});
listContact.setItems((ObservableList) contactForList.getContactList());
}
請說明具體問題是什麼 –
您是否已經檢查了右側的相關鏈接,例如http://stackoverflow.com/questions/19588029/customize-listview-in-javafx-with-fxml?rq=1? – jns
@NoamHacker我想知道我是否正確加載fxml。也許有另一種方法來創建自定義單元格。 – Poks