Skip to content

Instantly share code, notes, and snippets.

@jsfan3
Created April 23, 2019 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsfan3/9f9865c28b70b9e19c737a4ea65cace4 to your computer and use it in GitHub Desktop.
Save jsfan3/9f9865c28b70b9e19c737a4ea65cace4 to your computer and use it in GitHub Desktop.
Test of extending AutoCompleteTextField
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