Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GWT列表框OnChangeHandler_Gwt - Fatal编程技术网

GWT列表框OnChangeHandler

GWT列表框OnChangeHandler,gwt,Gwt,如何显式激发GWT列表框的OnChangeHandler 在我的场景中,当我调用ListBox的SetSelectedIndex(X)方法时应该触发它 试试任何一种: 重写setSelectedIndex()方法并触发ChangeEvent final ListBox lb = new ListBox() { @Override public void setSelectedIndex(int index) { super.setS

如何显式激发GWT列表框的OnChangeHandler

在我的场景中,当我调用ListBox的SetSelectedIndex(X)方法时应该触发它

试试任何一种:

重写
setSelectedIndex()
方法并触发
ChangeEvent

    final ListBox lb = new ListBox() {
        @Override
        public void setSelectedIndex(int index) {
            super.setSelectedIndex(index);
            DomEvent.fireNativeEvent(Document.get().createChangeEvent(), this);
        }
    };

重写
setSelectedIndex()
方法,并调用用于
ChangeHandler
的相同方法,给出相同的行为

public void onModuleLoad() {

    // Make a new list box, adding a few items to it.
    final ListBox lb = new ListBox() {
        @Override
        public void setSelectedIndex(int index) {
            super.setSelectedIndex(index);
            onChangeBody(this);
        }
    };
    lb.addItem("foo");
    lb.addItem("bar");
    lb.addItem("baz");
    lb.addItem("toto");
    lb.addItem("tintin");

    lb.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            onChangeBody(lb);
        }
    });

    // Make enough room for all five items (setting this value to 1 turns it
    // into a drop-down list).
    lb.setVisibleItemCount(5);

    // Add it to the root panel.
    RootPanel.get().add(lb);
}

public void onChangeBody(ListBox lb) {
    System.out.println(lb.getValue(lb.getSelectedIndex()));
}