在zk中需要给页面的按钮button 添加事件监听,同时弹出修改页面。
但是在监听事件类算是一个内部类。在内部类引用局部变量要求必须是final的,而引用全局变量就不需要。该怎样解决这个问题呢。
主要是在新建类都构造方法中加入外部类的局部变量,然后就可以传给内部类了
String netbar_id=netbar.getNetbar_id();//保存参数
Button detail=new Button();
detail.addEventListener(Events.ON_CLICK, new showEventListener(netbar_id));
class showEventListener implements EventListener{
String id;
public showEventListener(String netbar_id){
this.id=netbar_id;
}
@Override
public void onEvent(Event event) throws Exception {
Div div=new Div();
div.appendChild(new NetbarDetailWin(id));
win.appendChild(div);
}
}
本文介绍如何在ZK框架中为按钮添加事件监听,并通过内部类实现页面跳转。重点讨论了内部类引用局部变量时需声明为final的问题及解决方案。
3927

被折叠的 条评论
为什么被折叠?



