JavaFX ObservableList监听

	Callback, Observable[]> extractor = new                  Callback, Observable[]>() {
        @Override
        public Observable[] call(ObservableMap param) {
            List ObservableList = new ArrayList<>(param.values());
            Observable arr[] = new Observable[ObservableList.size()];
            return ObservableList.toArray(arr);
        }
    };

	ObservableList>> nodesList = = FXCollections.observableArrayList(extractor);
	ObservableMap map = FXCollections.observableHashMap();
	// map操作略
	nodesList.add(map);
	nodesList.addListener(createListChangeListener(poiMapLayer));
			
	private ListChangeListener> createListChangeListener(PoiMapLayer poiMapLayer){
		ListChangeListener> result = new ListChangeListener>() {
			@Override
			public void onChanged(Change> change) {
				while (change.next()) {
					if (change.wasPermutated()) {
						// 重新排列
					} else if (change.wasUpdated()) {
						// 更改
					} else if (change.wasReplaced()) {
					// 被替换
						// 删除
						List> removeList = change.getRemoved();
						for (ObservableMap observableMap : removeList) {
							map的value类型 map的value = (map的value类型)observableMap.get("map的key").getValue();
						}
						// 添加
						List> addList = change.getAddedSubList();
						for (ObservableMap observableMap : addList) {
						}
					} else {
						if (change.wasRemoved()) {
							// 删除
							List> removeList = change.getRemoved();
							for (ObservableMap observableMap : removeList) {
							}
						} else if (change.wasAdded()) {
							// 添加
							List> addList = change.getAddedSubList();
							for (ObservableMap observableMap : addList) {
							}
						}
					}
				}
			}	
		};
		
		return result;
	}

 

你可能感兴趣的:(Java,#,JavaFX)