Problems with dynamic autocompletetextfield.

11 views
Skip to first unread message

rdvg...@gmail.com

unread,
Mar 16, 2018, 6:36:18 PM3/16/18
to CodenameOne Discussions
Hi,

In another post, Shai explained a trick to allow a complete word to be written before launching the reading into the Database. I modified it a bit to allow one or several words to be written and the reading to be launched when I found a blank space.
I have 4 forms which apply the same principle but only 2 works perfectly, the other 2 do not show the list after the blank. To get the list displayed, I have to click anywhere in the form and click again on the autocompletetextfield.
Carefully review all routines and they are almost identical. I'm baffled and I need support to solve this silly situation (my code below).
Important: this only happens the first time you write on the component, after appearing the list can be rewritten and the list is updated without problem.

The following image shows the form that works perfectly by launching the list after the blank space.


The following images show another form that does not work after the blank space and a second image where you click on another point of the form and then on the component.


My Code:

        Data data = new Data();
        Container cnArticulos = new Container(BoxLayout.y());
        cnArticulos.setScrollableY(true);

        DefaultListModel lmArticulos = new DefaultListModel();
        AutoCompleteTextField acNombreArticulo = new AutoCompleteTextField(lmArticulos) {
            @Override
            protected boolean filter(String text) {
                if (text.length() == 0) {
                    return false;
                }
                char[] p = text.toCharArray();
                if (p.length == 0) {
                    return false;
                } else if (p[p.length - 1] != ' ') {
                        return false;
                    }
                }
                ArrayList l = dT.leeInformacionRegistro(text, ARTICULO_LEE_NOMBRE_REGISTRO);
                if (l == null || l.isEmpty()) {
                    return false;
                }
                if (l.size() < LIMITE_DATOS) {
                    Vector vArticulos = new Vector();
                    lmArticulos.removeAll();
                    for (int i = 0; i < l.size(); i++) {
                        Articulo aRt = registroArticulo((Map<String, String>) l.get(i));
                        lmArticulos.addItem(aRt.getNombre());
                        vArticulos.addElement(aRt);
                    }
                    data.setArticulos(vArticulos);
                    Vector vArticuloEvaluacion = new Vector();
                    l = dT.leeInformacionRegistro(text, ARTICULO_EVALUACION_LEE_FILTRO_ARTICULO);
                    if (l != null) {
                        for (int i = 0; i < l.size(); i++) {
                            ArticuloEvaluacion aEv = registroArticuloEvaluacion((Map<String, String>) l.get(i));
                            vArticuloEvaluacion.addElement(aEv);
                        }
                    }
                    data.getArticuloEvaluacion();
                } else {
                    Dialog.show(idioma.getInformacion(), idioma.getMensaje21(), idioma.getContinuar(), null);
                }
                return true;
            }
        };






Shai Almog

unread,
Mar 17, 2018, 12:47:21 AM3/17/18
to CodenameOne Discussions
Hi,
I'm guessing you are referring to the UITimer trick I mentioned to delay the reading call?
UITimer is bound to a specific form so is it possible you used that trick and bound it to a different form instance? A UITimer will only tick when the form is visible.
Reply all
Reply to author
Forward
0 new messages