javafx - JavaFXPorts: Selected item in ListView is not selected -
here sample code:
package com.javafxportslistviewdemo; import com.gluonhq.charm.down.platform; import com.gluonhq.charm.down.services; import com.gluonhq.charm.down.plugins.lifecycleevent; import com.gluonhq.charm.down.plugins.lifecycleservice; import javafx.application.application; import javafx.beans.value.observablevalue; import javafx.collections.fxcollections; import javafx.collections.observablelist; import javafx.geometry.rectangle2d; import javafx.scene.scene; import javafx.scene.control.label; import javafx.scene.control.listview; import javafx.scene.input.keycode; import javafx.scene.input.keyevent; import javafx.scene.layout.vbox; import javafx.stage.screen; import javafx.stage.stage; public class javafxportslistviewdemo extends application { @override public void init() { } @override public void start(stage primarystage) throws exception { screen primaryscreen = screen.getprimary(); rectangle2d visualbounds = primaryscreen.getvisualbounds(); double width = visualbounds.getwidth(); double height = visualbounds.getheight(); label label = new label("here selected item..."); listview<string> listview = new listview<>(); observablelist<string> items = fxcollections.observablearraylist( "one", "two", "three", "four"); listview.setitems(items); listview.getselectionmodel().selecteditemproperty().addlistener((observablevalue<? extends string> ov, string old_val, string new_val) -> { label.settext(new_val); }); vbox root = new vbox(); root.getchildren().addall(label, listview); scene scene = new scene(root, width, height); services.get(lifecycleservice.class).ifpresent(ls -> { ls.addlistener(lifecycleevent.pause, () -> onpause()); ls.addlistener(lifecycleevent.resume, () -> onresume()); }); scene.addeventhandler(keyevent.key_released, e -> { if (keycode.escape.equals(e.getcode())) { if (platform.isandroid()) { // bring menu or other android stuff services.get(lifecycleservice.class).ifpresent(lifecycleservice::shutdown); } else { // bring menu or other desktop stuff services.get(lifecycleservice.class).ifpresent(lifecycleservice::shutdown); } } }); primarystage.setscene(scene); primarystage.show(); } private void onpause() { } private void onresume() { } }
environment development: javafxports 8.60.8, javafxmobile-plugin 1.1.0, gluon plugin 2.4.0, netbeans 8.1, windows 10 pro, 64-bit
environment testing: android device samsung galaxy a5 2016, android 6.0.1
steps reproduce: 1. build sample code with: javafxports 8.60.8, javafxmobile-plugin 1.1.0, gluon plugin 2.4.0; 2. install , run sample on android device (android 6.0.1); 3. touch on listview , select item listview - item not selected -> bug
added bug issue tracker of javafxports: javafxports issue
thanks reporting issue.
it known in samsung devices touch event handling doesn't work in rest of android devices.
while fixed in javafxports, can use following workaround: provide listener listcell
wires internally selection.
based on 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));
Comments
Post a Comment