How to know from ListChangeListener.Change about which elements were removed?

被刻印的时光 ゝ 提交于 2019-12-11 14:26:01

问题


ObservableList is ordered by nature and most access and reportings are index-based. But suddenly, when reporting about removements, they switched to value-based approach.

Why?

I have second list, which is carrying additional information for ObservableList and want to keep it in sync with ObservableList. I can track permutations, updatings and additions, but I can't track removements.

Why?

How to know the indices of removed elements from ObservableList? Is it possible?

JavaFX 8 doc is here: http://docs.oracle.com/javase/8/javafx/api/javafx/collections/ListChangeListener.Change.html

UPDATE

Suppose I have ObservableList, which is containing 5 consequent identical values, for example, strings "person", "person", "person", "person", "person". Now I remove 3 last persons. How can I know that namely last 3 persons removed, if getRemoved() will show me just three values?


回答1:


I found that on delete, the method getFrom() contains the starting index of deletion, and the method getRemovedSize() gives the number of deleted elements from that index. This information is enough to modify synched list.



来源:https://stackoverflow.com/questions/24013690/how-to-know-from-listchangelistener-change-about-which-elements-were-removed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!