It is not distinguished when a Container is selected.

11 views
Skip to first unread message

rdvg...@gmail.com

unread,
Aug 4, 2018, 1:38:39 PM8/4/18
to CodenameOne Discussions
Hi
I have a set of containers that are displayed in a list. I trigger a method without problem when a container is selected but I can not change it.

Next I show my code so that they indicate to me that I am doing badly.

    // Método que devuelve el detalle de las tiendas
    private SwipeableContainer creaItemTienda(Form fmTienda, Tienda tDa) {

        Label lbImagen = new Label();
        lbImagen.setUIID("Transparent");
        lbImagen.setIcon(imagenTipoTienda(tDa.getTipoTienda()));

        Button txNombre = new Button();
        txNombre.setUIID("MultiLine2");
        txNombre.setText(tDa.getNombre());

        TextArea txDireccion = new TextArea(2, 60);
        txDireccion.setUIID("MultiLine3");
        txDireccion.setText(tDa.getDireccion());
        txDireccion.setEditable(false);
        txDireccion.setAlignment(TextArea.LEFT);

        Label lbEvaluacion = new Label(" (" + tDa.getEvaluacionCantidad() + ")");
        lbEvaluacion.setIcon(res.getImage(imagenEvaluacion(tDa.getEvaluacion())));
        lbEvaluacion.setTextPosition(Label.RIGHT);

        Style s = UIManager.getInstance().getComponentStyle("LabelYellow");
        Button btEvaluar = new Button(FontImage.createMaterial(FontImage.MATERIAL_STAR, s, 8), "Transparent");

        //    Container cnEvaluacion = LayeredLayout.encloseIn(lbEvaluacion, FlowLayout.encloseRight(btEvaluar));
        Container cnDatos = new Container(new BoxLayout(BoxLayout.Y_AXIS)).add(txNombre).add(txDireccion);
        Container cnDatos1 = new Container(new BoxLayout(BoxLayout.Y_AXIS)).add(cnDatos).add(lbEvaluacion);
        Container cnItem = new Container(new BoxLayout(BoxLayout.X_AXIS)).add(lbImagen).add(cnDatos1);
        Container cnElemento = new Container(new BoxLayout(BoxLayout.Y_AXIS)).add(cnItem).add(separador());
        cnElemento.setLeadComponent(txNombre);

        s = UIManager.getInstance().getComponentStyle("Menu");
        FontImage iMapa = (FontImage) FontImage.createMaterial(FontImage.MATERIAL_LOCATION_ON, s, 8);
        if (tDa.getUrl().length() == 0) {
            iMapa = (FontImage) FontImage.createMaterial(FontImage.MATERIAL_LOCATION_OFF, s, 8);
        }
        Button btMapa = new Button(iMapa, "Transparent");
        Container cnBotones = new Container(new BoxLayout(BoxLayout.X_AXIS)).add(btMapa).add(btEvaluar);
        cnBotones.setUIID("Transparent");

        SwipeableContainer sc = new SwipeableContainer(
                cnBotones,
                null,
                //                GridLayout.encloseIn(1, btEliminar),
                cnElemento);
        sc.putClientProperty("busqueda", tDa.getNombre() + tDa.getDireccion());

        txNombre.addActionListener((e) -> {
            mantenimientoTienda(fmTienda, tDa, CAMBIAR);
        });
        btMapa.addActionListener((e) -> {
            if (tDa.getUrl().length() > 0) {
                Display.getInstance().execute(tDa.getUrl());
            }
        });
        btEvaluar.addActionListener((e) -> {
            muestraEvaluacion(fmTienda, sc, null, null, tDa, null, null, TIENDA);
        });
        return sc;
    }

Shai Almog

unread,
Aug 5, 2018, 12:22:48 AM8/5/18
to CodenameOne Discussions
Hi,
I'm assuming you mean BoxLayout Y and not in a renderer within a List...

I suggest you don't use the Container UIID and instead use a different UIID if you want to control the background as the Container UIID is a special case in Codename One.

Normally to select a Container it needs to be focusable but that would make it "steal" the focus from the components. If you want an entire component hierarchy to behave as one component you should use lead component. See the explanation of lead component here: https://www.codenameone.com/manual/components.html
Reply all
Reply to author
Forward
0 new messages