问题
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