JavaFXPorts: Selected item in ListView is not selected

 ̄綄美尐妖づ 提交于 2019-11-29 16:00:16

Thanks for reporting the issue.

It is already known that in some Samsung devices the touch event handling doesn't work as in the rest of Android devices.

While this is fixed in JavaFXPorts, you can use the following workaround: provide a listener to the ListCell that wires internally the selection.

Based on your sample:

    ListView<String> listView = new ListView<>();
    listView.setCellFactory(p -> new ListCell<String>() {

        private String item;
        {
            setOnMouseClicked(e -> listView.getSelectionModel().select(item));
        }

        @Override
        protected void updateItem(String item, boolean empty) {
            super.updateItem(item, empty); 
            this.item = item;
            setText(item);
        }

    });
    listView.getSelectionModel().selectedItemProperty()
      .addListener((ov, old_val, new_val) -> label.setText(new_val));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!