How to add a OnKeyPressed like listener on a textfield

126 views
Skip to first unread message

Fabrice Kabongo

unread,
Jul 17, 2013, 5:12:10 AM7/17/13
to codenameone...@googlegroups.com
I have to do countdown of place remaining on a fieldtext, i didn't find something like a OnKeyPressed listener. i've just tried with a actionEvent listener but it's update my countdown only when the user quit(take off the focus from the text field) the textfield.

It looks like this:

protected void onActualite_BreveContenuAction(Component c, ActionEvent event)
{
    findActualiteCaractereCount
().setText(String.valueOf(160-findBreveContenu().getText().length()));
   
}


Shai Almog

unread,
Jul 17, 2013, 11:57:20 AM7/17/13
to codenameone...@googlegroups.com
You need to use data change listener not key listener since the virtual keyboards don't broadcast key events.

Shai Almog

unread,
Jul 17, 2013, 11:58:10 AM7/17/13
to codenameone...@googlegroups.com
Just so I'm clear, in the before show of the form use findMyTextField(f).addDataChangeListener(....);
Message has been deleted

Fabrice Kabongo

unread,
Jul 17, 2013, 5:42:27 PM7/17/13
to codenameone...@googlegroups.com
Tested and approuved!!! lol!! it's work very well!!! thank Mr shai 
Reply all
Reply to author
Forward
0 new messages