TextFields - dataChanged method not called in listener (simulator)

17 views
Skip to first unread message

P5music

unread,
Jan 4, 2021, 6:22:39 AM1/4/21
to CodenameOne Discussions
My CodenameOne app features a container for editing. It contains some TextFields, Buttons and other components.
I need to know when the text has changed inside a TextField, but I see that the listener is called only after another component has been focused.

editText.addDataChangedListener(new DataChangedListener() {
@Override
public void dataChanged(int type, int index) {
setEdited();
}
});

This method is called

public void setEdited()
    {
       // System.out.println("edited");  event not fired
           System.out.println("edited"); event fired
...
...

    }

In the method you can see that a logging instruction is present.
If it is present the event is fired.
If it is commented the event is not fired.

Is this a behaviour that will be found also on devices?
Or it is just one of simulator's whims?

Thanks in advance

Shai Almog

unread,
Jan 4, 2021, 10:14:00 PM1/4/21
to CodenameOne Discussions
Data changed is invoked as you type in the simulator too. Not sure what you're seeing here...

P5music

unread,
Jan 5, 2021, 3:49:36 AM1/5/21
to CodenameOne Discussions
Yes, you are right. I checked and it is not matter of events being called or not.
The setEdited() method in fact sets the icon of the save button.
This icon is different according to the saved or unsaved state of the editing container.
If the data are unsaved the icon changes to represent a reminder for the user, although the user will be asked to save anyway. 

So the issue is in the setIcon method.
The icons are created in Java code (Flamingo).
The complete call is
setIcon(buttonIcon.scaled(doubleButtonSize,doubleButtonSize).toImage());
This could be a matter of UI refresh, like it happens for the BrowserComponent (it has to be "touched" to update the content or the appearance).
Regards

Shai Almog

unread,
Jan 5, 2021, 10:14:17 PM1/5/21
to CodenameOne Discussions
Did you revalidate/repaint?
When changing a UI you need to refresh when you're done. Codename One doesn't auto-reflow.
Reply all
Reply to author
Forward
0 new messages