Touch event handling problem

62 views
Skip to first unread message

dmitry.p...@gmail.com

unread,
Oct 22, 2013, 4:46:22 PM10/22/13
to codenameone...@googlegroups.com
Hi! I am struggling with handling touch events in Codename One and I wonder if anyone has faced the same problem before.
Basically, I have a Container with vertical box layout that is scrollable in y-direction and it is filled with containers with horizontal box layout. The inner containers override pointer functions (pointerPressed(int x, int y), pointerDragged(int x, int y) and pointerReleased(int x, int y)) to enable custom flick gestures. And this makes the parent container not scrollable any more. Is there a way to keep both parent and children respond to touch events?

See code below for a simpler demo of this problem. When inner containers are set to scrollableX, the parent container is no longer scrollableY.


Form test = new Form("test");

            Container c = new Container(new BoxLayout(BoxLayout.Y_AXIS));
            c.setScrollableY(true);
            test.addComponent(c);

            for (int i = 0; i <= 5; i++) {
                Container c1 = new Container(new BoxLayout(BoxLayout.X_AXIS));
                c1.getUnselectedStyle().setBorder(Border.getDefaultBorder());
                c1.setPreferredSize(new Dimension(Display.getInstance().getDisplayWidth(), 100));
                c1.setScrollableX(true);
                c1.addComponent(new Button("Button " + i));
                Label l = new Label("Label " + i);
                l.setPreferredW(Display.getInstance().getDisplayWidth());
                c1.addComponent(l);
                c.addComponent(c1);
            }

            test.show();

Thanks! 

Chen Fishbein

unread,
Oct 23, 2013, 2:31:21 AM10/23/13
to codenameone...@googlegroups.com, dmitry.p...@gmail.com
Hi,
The code snippet you provided work just fine on both axis.(make sure your plugin and local libs are up to date).
Also when you override the pointer functions make sure to call super to move the event to the parent container

dmitry.p...@gmail.com

unread,
Oct 23, 2013, 11:23:39 AM10/23/13
to codenameone...@googlegroups.com, dmitry.p...@gmail.com
Thanks! You were right: my library was out of date, it works fine now.
Reply all
Reply to author
Forward
0 new messages