android listview 不重绘,javafx listview和treeview控件没有被正确重绘

javafx listview和treeview控件没有被正确重绘

我试图把元素放在一个ListView和TreeView与javafx,但两个控件都不会刷新它们的内容。 我正在使用obvservable列表来控制项目,每次我删除一个项目时,listview或treeview从数据源中删除它。 但是视图不更新。 我仍然看到所有的项目。 唯一的区别是,删除的项目不能再被选中。 例如链接2显示了拼合的项目列表。 图片1显示了它们拼合之前的项目。 项目被折叠,但旧的条目仍然可见。 有没有人知道这个问题的解决scheme。 谢谢大家帮助我

链接1: treeview不折叠链接2: treeview被折叠,但不更新旧的视图

这是我用来显示一个列表视图的自定义单元格工厂:

public ListCell call(final ListView param) { ListCell cell = new ListCell(){ @Override protected void updateItem(final T persistentObject, final boolean empty) { super.updateItem(persistentObject, empty); if(persistentObject instanceof POProcessStep){ POProcessStep poProcessStep = (POProcessStep) persistentObject; if (persistentObject != null) { super.setText(poProcessStep.getId() + " - " + poProcessStep.getTitle()); } }else if(persistentObject instanceof POProcess){ POProcess poProcess = (POProcess) persistentObject; if (persistentObject != null) { super.setText(poProcess.getId() + " - " + poProcess.getTitle()); } }else if(persistentObject instanceof POCategory){ POCategory poCategory = (POCategory) persistentObject; if(persistentObject != null){ super.setText(poCategory.getId() + " - " + poCategory.getTitle()); } }else if(persistentObject instanceof String){ if(persistentObject != null){ super.setText(String.valueOf(persistentObject)); } } super.setGraphic(null); } }; return cell; }

您的单元工厂的updateItem(...)需要处理单元格为空的情况。 当项目项目被删除(或者由于TreeView一个节点被折叠而变为空白)并且以前显示一个项目的单元格被重用为空单元格时,

public ListCell call(final ListView param) { ListCell cell = new ListCell(){ @Override protected void updateItem(final T persistentObject, final boolean empty) { super.updateItem(persistentObject, empty); if (empty) { setText(null); setGraphic(null); } else { // ... rest of your code. } } } return cell ; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值