codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.72k stars 409 forks source link

RFE: add an API to programmatically close the popup of an AutoCompleteTextField #2788

Closed jsfan3 closed 5 years ago

jsfan3 commented 5 years ago

Can you please add an API to programmatically close the popup of an AutoCompleteTextField, when the popup is shown?

My problem is that I have a Contacts page in which the user can autocomplete its address and other data (there are several AutoCompleteTextField in the same Form)... but, if he/she leaves the popup opened (without tapping any item of the list) and press a Button that removes the AutoCompleteTextFields to show other content (in the same Form), the popup remains like in the following screenshot. I thought that a solution is to close programmatically any popup shown, if there is one.

screenshot

jsfan3 commented 5 years ago

Test case to be more clear:

Form hi = new Form("Popup test", BorderLayout.absolute());
        AutoCompleteTextField autocomplete = new AutoCompleteTextField("1", "2", "3");
        Button tapMe = new Button("Tap me leaving the popup opened");
        tapMe.addActionListener(l -> {
            hi.replace(autocomplete, new Label("other content"), null);
            hi.revalidate();
        });
        hi.add(BorderLayout.CENTER, autocomplete);
        hi.add(BorderLayout.NORTH, tapMe);
        hi.show();

If you type "2" in the AutoCompleteTextField and then press the button, you will get the following wrong UI, because the popup is still shown without any chance to remove it:

popup

What I'm asking is a new method closePopup(), to be used so:

tapMe.addActionListener(l -> {
            autocomplete.closePopup();
            hi.replace(autocomplete, new Label("other content"), null);
            hi.revalidate();
        });

or, alternatively, a fix that automatically close the popup if the AutoCompleteTextField is removed or replaced (maybe this is better).

shannah commented 5 years ago

There was a bug in the deinitialization code that caused the popup removal to fail. I have fixed this so that the popup is automatically removed.

I've added a sample for this issue as well.

jsfan3 commented 5 years ago

Thank you