Method "PropertyValue" returns a null value in Component Contenair, does not allow to make fitted.

20 views
Skip to first unread message

rube...@yahoo.com

unread,
May 19, 2017, 12:13:35 AM5/19/17
to CodenameOne Discussions
Hi,

I have a list of containers where each element assigned a value in the "setPropertyValue" method as shown in my code:

    private void adicionArticulo(Container cnArticulo, Articulo aRt) {

        TextArea txNombre = new TextArea();
        txNombre.setText(aRt.getNombre());
        txNombre.setEditable(false);

        Container cnElemento = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        cnElemento.addComponent(txNombre);
        cnElemento.setPropertyValue("busqueda", aRt.getNombre() + aRt.getSerial());

        cnArticulo.addComponent(cnElemento);
        cnArticulo.animateLayout(200);
    }

The problem is when trying to filter the items in the container list because the method "getPropertyValue" comes in null

        Container cnArticulos = new Container();
        cnArticulos.setScrollableY(true);
        devuelveArticulos(cnArticulos);

        txBusqueda.addDataChangeListener((int type, int index) -> {
            String t = txBusqueda.getText();
            if (t.length() < 1) {
                for (Component cmp : cnArticulos) {
                    cmp.setHidden(false);
                    cmp.setVisible(true);
                }
            } else {
                t = t.toLowerCase();
                for (Component cmp : cnArticulos) {
                    boolean show = false;
                    String val = null;
                    if (cmp instanceof Container) {
                        val = (String) cmp.getPropertyValue("busqueda");
                    }
                    show = val != null && val.toLowerCase().indexOf(t) > -1;
                    cmp.setHidden(!show);
                    cmp.setVisible(show);
                }
            }
            cnArticulos.animateLayout(250);
        });

    // Método que devuelve la lista de artículos que existen en Liber
    private void devuelveArticulos(Container cnArticulo) {

        Vector vArticulo = dT.getArticulos();
        for (int i = 0; i < vArticulo.size(); i++) {
            Articulo aRt = (Articulo) vArticulo.elementAt(i);
            adicionArticulo(cnArticulo, aRt);
        }
    }

Shai Almog

unread,
May 19, 2017, 12:45:04 AM5/19/17
to CodenameOne Discussions, rube...@yahoo.com
Hi,
that's not how it works. That method was created for the old GUI builder since we don't have support for reflection.

I'm assuming that what you are really looking for is put/getClientProperty().

rube...@yahoo.com

unread,
May 19, 2017, 11:02:50 AM5/19/17
to CodenameOne Discussions, rube...@yahoo.com
Thanks.
Reply all
Reply to author
Forward
0 new messages