当用户点击从数据库中检索到的特定约会时,我想打印预约summary
和description
。
我试图通过以下方式实现此目的:
lAgenda.selectedAppointments().addListener(new ListChangeListener<Appointment>() {
@Override
public void onChanged(Change<? extends Appointment> c) {
System.out.println(c.toString());
}
});
然而,我只能得到这个:
com.sun.javafx.collections.NonIterableChange$GenericAddRemoveChange@1ef0f08
com.sun.javafx.collections.NonIterableChange$SimpleAddChange@1c3e48b
com.sun.javafx.collections.NonIterableChange$GenericAddRemoveChange@d57e70
com.sun.javafx.collections.NonIterableChange$SimpleAddChange@6022e2
com.sun.javafx.collections.NonIterableChange$GenericAddRemoveChange@54ddc1
如何检索其他项目,例如从中检索约会的数据库行中的行ID?谢谢大家。
答案 0 :(得分:1)
您正在使用正确的属性来通知选择更改。
您收到了ListChangeListener.Change。如javadoc中所述,应该以这种方式使用更改:
lAgenda.selectedAppointments().addListener(new ListChangeListener< Appointment >() {
public void onChanged(Change<? extends Appointment> c) {
while (c.next()) {
if (c.wasPermutated()) {
for (int i = c.getFrom(); i < c.getTo(); ++i) {
//permutate
}
} else if (c.wasUpdated()) {
//update item
} else {
for (Appointment a : c.getRemoved()) {
}
for (Appointment a : c.getAddedSubList()) {
printAppointment(a);
}
}
}
}
});
现在,您可以打印出appointment摘要和说明:
private void printAppointment(Appointment a) {
System.out(a.getSummary());
System.out(a.getDescription());
}
如果您需要约会对象的某些特定属性(如数据库ID),您可以通过扩展AppointmentImpl或实施Appointment来创建约会类