0

我正在使用 gwt 中的建议框,并将 SelectionHandler 和 onFocusHandler 添加到建议框中,但选择后建议列表仍然可见。这不应该是这种情况。

选择其中一项建议后,我应该怎么做才能隐藏建议列表。?

suggestBox.getValueBox().addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            if(suggestBox.getText().equals("")){
                suggestBox.setText(" ");
                suggestBox.showSuggestionList();
                suggestBox.setText("");
            }   
        }
    });

suggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {

        @Override
        public void onSelection(SelectionEvent<Suggestion> arg0) {
            if (arg0.getSelectedItem() instanceof Suggestion) {
                //code to take actions after selection
            }
        }
    });
4

1 回答 1

2

选择其中一项建议后,我应该怎么做才能隐藏建议列表。?

为什么不在选择处理程序中隐藏列表?

    @Override
    public void onSelection(SelectionEvent<Suggestion> arg0) {
        if (arg0.getSelectedItem() instanceof Suggestion) {
            //code to take actions after selection
        }
        DefaultSuggestionDisplay display = (DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay();
        display.hideSuggestions();
    }
于 2015-12-29T12:47:38.677 回答