detect pointer is pressed several seconds on TextField

38 views
Skip to first unread message

shop.servic...@gmail.com

unread,
Jul 17, 2017, 9:15:32 AM7/17/17
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA NetBeans 8.2
Desktop OS Windows 10
Simulator 3.7
Device Android & IOS

I want to take an action when a user touches and holds a Text Field for say 2 seconds.
Currently pressing and releasing brings focus and editing to that field. This is Ok.

However if held for >= 2 seconds, I want to perform a different action on this data.

Thoughts?

PS:
            VinText.addPointerPressedListener(e -> {
                try {
                    e.consume();
                    Dialog.show("VINText Event", "Event isLongEvent = [" + e.isLongEvent() + "] Type = " + e.getEventType(), "OK", null);
                } catch (Exception er) {
                    er.printStackTrace();
                }
            });
Returns my Dialog immediately. Don't know how to determine if this was pressed for a period of time.
Also e.isLongEvent() returned false

I have looked at addActionListener results, it returns Edit and LongEvent = false when I press and hold this field for say 2 or more seconds.

Shai Almog

unread,
Jul 18, 2017, 12:17:11 AM7/18/17
to CodenameOne Discussions, shop.servic...@gmail.com
Text input is handled natively in Codename One as it's a pretty special case.

Overriding the native editing behavior isn't a good direction.

shop.servic...@gmail.com

unread,
Jul 18, 2017, 10:38:56 AM7/18/17
to CodenameOne Discussions, shop.servic...@gmail.com
Any suggestions on how to capture an event when  a user touches and holds a Text Field for say 2 seconds then upon release I will take an action.

Shai Almog

unread,
Jul 19, 2017, 1:03:25 AM7/19/17
to CodenameOne Discussions, shop.servic...@gmail.com
You can derive and override the component and the longPress callback but as I said before that's a bad idea.
Reply all
Reply to author
Forward
0 new messages