I have one listView and one checked ListView which need to interact with each other. Photo
When i select an element from listView, checked ListView should show me checked items (in one method) and be able to add or remove elements(another method).
//Method_One
protected void methodOne() {
listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Role>() {
@Override
public void changed(ObservableValue<? extends Role> observable, Role oldValue, Role newValue) {
r = newValue;
Query query = jpa.getEntityManager().createQuery("SELECT v FROM Views v WHERE v.idRole =:idRole");
query.setParameter("idRole", r);
List rez = query.getResultList();
checkedListView.getCheckModel().clearChecks();
Iterator<Views> it_view = rez.iterator();
while (it_view.hasNext()) {
Views v = it_view.next();
int i = v.getIdViews();
checkedListView.getCheckModel().check(i - 2);
}
}
});
}
//Method_Two
private void methodTwo() {
checkedListView.getCheckModel().getCheckedItems().addListener(new ListChangeListener<Views>() {
@Override
public void onChanged(ListChangeListener.Change<? extends Views> c) {
c.next();
if (c.wasAdded()) {
System.out.println("Item Checked : " + c.getAddedSubList().get(0));
} else if (c.wasRemoved()) {
System.out.println("Item Unchecked : " + c.getRemoved().get(0));
}
}
});
}
Problem is when i select an element on ListView it addes duplicated elements of checkedListView.
Aucun commentaire:
Enregistrer un commentaire