JavaFXPorts: Is this correct behavior for javafx.scene.control.ComboBox on Android device?

后端 未结 2 2098
有刺的猬
有刺的猬 2021-01-27 17:17

After selecting item in ComboBox, then this selected item is not displayed in ComboBox - only Android device, on desktop is it ok. Compare this two screenshots:


[O

2条回答
  •  半阙折子戏
    2021-01-27 17:36

    Based on Josés answer I've implemented the following generic Helper function, which might help some of you:

    public static  void removeSelectionBug(ComboBox comboBox) {
        comboBox.setCellFactory(p -> new ListCell() {
            private T item;
            {
                setOnMousePressed(e -> comboBox.getSelectionModel().select(item));
            }
    
    
            @Override
            protected void updateItem(T item, boolean empty) {
                super.updateItem(item, empty);
                this.item = item;
                if (item != null) {
                    setText(item.toString());
                }
            }
        });
    }
    

    Btw: I've got this bug on all of my Mobiles(Samsung Note 3, Sony XPERIA Z3 Compact and Nexus 4)

提交回复
热议问题