Get suggested value from AutoCompleteTextField when actionPerformed

34 views
Skip to first unread message

mikko.nu...@gmail.com

unread,
May 19, 2015, 9:56:43 AM5/19/15
to codenameone...@googlegroups.com
Hi,

I'm using AutoCompleteTextField to suggest contacts from user's phone. User may add several ones, so I'm adding the names to other list when action is performed. It appears that getText() only returns the typed text at this point, not the one that is just selected from the the list. For example if I write "Bart" and select "Bart Simpson", getText() returns "Bart". Is there a way to get the actual selected value with this listener at this point? I know that it is doable if use for example data changed listener but then I'd have to validate the getText() from the contacts every time data is changed. Is there a better way to do this?

  participant.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                if (ObjectUtils.isNotNullOrEmpty(participant.getText())) {
                    participantList.addItem(participant.getText());
                }
            }
        });

Shai Almog

unread,
May 19, 2015, 10:31:41 AM5/19/15
to codenameone...@googlegroups.com, mikko.nu...@gmail.com, mikko.nu...@gmail.com
Hi,
I think your event is happening before the event chain completed. If you just wrap the body of the method (what's inside the "actionPerformed" method) with a callSerially this will postpone it to the next event dispatch cycle and allow the text to be set to the full text.

mikko.nu...@gmail.com

unread,
May 20, 2015, 4:13:44 AM5/20/15
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
Hi,

that didn't seem to help... I guess I have to go with the DataChangedListener.
Reply all
Reply to author
Forward
0 new messages