-
-
Save jsfan3/9f9865c28b70b9e19c737a4ea65cace4 to your computer and use it in GitHub Desktop.
Test of extending AutoCompleteTextField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AutoCompleteTextField field = new AutoCompleteTextField(listModel) { | |
@Override | |
protected boolean filter(String text) { | |
return getCityFilter(listModel, resultQuery, isFullAddressSearch).filter(text); | |
} | |
// https://github.com/codenameone/CodenameOne/issues/2757#event-2268199434 | |
@Override | |
protected boolean shouldShowPopup() { | |
return isEditable(); | |
} | |
@Override | |
public void setEditable(boolean isEditable) { | |
super.setEditable(isEditable); | |
if (!isEditable) { | |
this.removePopup(); | |
} | |
} | |
/** | |
* It's not safe: it can throw an Exception | |
*/ | |
private void removePopup() { | |
Form f = getComponentForm(); | |
Component popup; | |
if (f != null) { | |
popup = ComponentSelector.$("AutoCompletePopup", f).asComponent(); | |
if (popup != null) { | |
// Keep attention: "popup.remove()" throws an Exception in some circumstances, | |
// see: http://disq.us/p/21cb38g | |
Container lay = f.getLayeredPane(super.getClass(), true); | |
Container parent = popup.getParent(); | |
lay.removeComponent(parent); | |
// popup.remove(); | |
f.revalidate(); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment