Hi,
I have a list that is composed of a set of containers as shown in the
figure. As you can see, there are 2 buttons that increase or decrease the
quantity field by one unit (yellow circle). Each time I press the buttons
the total amount updates smoothly, but the amount remains the same.
Additionally, I need the quantity field to be able to be modified by the
user without using the buttons.
I appreciate the support
My code:
private Container creaItemInventario(VehiculoInventario iNv) {
TextArea *txCantidad* = new TextArea(iNv.cantidadPedido.get() !=
null ? iNv.cantidadPedido.get().toString() : "0");
txCantidad.setUIID("MultiLine3");
TextArea txPrecio = new TextArea(redondear(iNv.precio.get(), 2));
txPrecio.setUIID("MultiLine3");
txPrecio.setEditable(false);
TextArea txMonto = new TextArea();
txMonto.setUIID("LabelPupleTitle");
txPrecio.setEditable(false);
MultiButton mNombreArticulo = new MultiButton();
mNombreArticulo.setTextLine1(iNv.descripcionArticulo.get());
mNombreArticulo.setUIIDLine1("MultiLine2");
mNombreArticulo.setTextLine2(iNv.codigo.get() + " (" +
iNv.tamano.get() + ")");
mNombreArticulo.getAllStyles().setBgTransparency(150);
mNombreArticulo.setHorizontalLayout(false);
calculoMonto(txCantidad, txPrecio, txMonto, 0d);
Container cnPrecio = new Container(new
BoxLayout(BoxLayout.X_AXIS)).add(usr.simboloMoneda.get()).add(txPrecio.getText());
BorderLayout border = new BorderLayout();
border.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
Container cnMonto = new Container(border).add(BorderLayout.CENTER,
txMonto);
cnMonto.setUIID("LabelPurpleTitle");
Button btMenos = new
Button(FontImage.createMaterial(FontImage.MATERIAL_REMOVE,
UIManager.getInstance().getComponentStyle("Button")));
btMenos.addActionListener((e) -> {
if (Double.parseDouble(txCantidad.getText()) > 1) {
calculoMonto(*txCantidad*, txPrecio, txMonto, -1d);
}
});
Button btMas = new
Button(FontImage.createMaterial(FontImage.MATERIAL_ADD,
UIManager.getInstance().getComponentStyle("Button")));
btMas.addActionListener((e) -> {
calculoMonto(*txCantidad*, txPrecio, txMonto, +1d);
});
Style s = UIManager.getInstance().getComponentStyle("Menu");
BorderLayout border1 = new BorderLayout();
border1.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
s = UIManager.getInstance().getComponentStyle("ButtonRed");
Button btEliminar = new
Button(FontImage.createMaterial(FontImage.MATERIAL_DELETE, s, 8));
btEliminar.setUIID("ButtonTransparent");
Label lbImagenInventario = new Label();
FontImage.setMaterialIcon(lbImagenInventario,
FontImage.MATERIAL_LOCAL_SHIPPING, 7);
Label lbInventario = new Label(Double.toString(iNv.cantidad.get()));
lbInventario.setUIID("MensajeRojo");
FloatingActionButton badgeInventario =
FloatingActionButton.createBadge("");
badgeInventario.setText(lbInventario.getText());
badgeInventario.setUIID("MensajeRojo");
Label lbImagenInventarioEmpresa = new Label();
FontImage.setMaterialIcon(lbImagenInventarioEmpresa,
FontImage.MATERIAL_HOME_WORK, 7);
Label lbInventarioEmpresa = new
Label(Double.toString(iNv.cantidadInventario.get()));
FloatingActionButton badgeInventarioEmpresa =
FloatingActionButton.createBadge("");
badgeInventarioEmpresa.setText(lbInventarioEmpresa.getText());
badgeInventarioEmpresa.setUIID("MensajeRojo");
Container cnInventario = new Container(new GridLayout(1, 2));
cnInventario.add(badgeInventario.bindFabToContainer(lbImagenInventario,
Component.RIGHT, Component.CENTER));
cnInventario.add(badgeInventarioEmpresa.bindFabToContainer(lbImagenInventarioEmpresa,
Component.RIGHT, Component.CENTER));
Container cnCantidad = new Container(new GridLayout(1,
3)).add(btMenos).add(txCantidad.getText()).add(btMas);
Container cnCentro = new Container(new
BoxLayout(BoxLayout.Y_AXIS)).add(cnPrecio).add(cnCantidad);
Container cnItem = new Container(new BorderLayout());
cnItem.add(BorderLayout.NORTH, mNombreArticulo);
cnItem.add(BorderLayout.EAST, cnMonto);
cnItem.add(BorderLayout.WEST, cnCentro);
cnItem.add(BorderLayout.SOUTH, cnInventario);
Style sItem = cnItem.getUnselectedStyle();
sItem.setBgTransparency(255);
sItem.setBgColor(0xeeeeee);
sItem.setMarginUnit(Style.UNIT_TYPE_DIPS);
sItem.setPaddingUnit(Style.UNIT_TYPE_DIPS);
sItem.setMargin(1, 0, 1, 1);
sItem.setPadding(1, 1, 1, 1);
cnItem.putClientProperty("busqueda", iNv.descripcionArticulo.get());
cnItem.putClientProperty("registro", iNv);
mNombreArticulo.addActionListener((e) -> {
cnItem.revalidate();
Dialog.show("Mensaje", "Pendiente", "continuar", null);
});
return cnItem;
}
private void calculoMonto(TextArea *txCantidad*, TextArea txPrecio,
TextArea txMonto, Double incremento) {
*txCantidad*.setText(Double.toString(Double.parseDouble(*txCantidad*.getText())
+ incremento));
Double c = Double.parseDouble(txCantidad.getText());
Float p = Float.parseFloat(txPrecio.getText());
txMonto.setText(redondear(p * c, 2));
this.revalidate();
}
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/414b29a5-b0b9-4eb6-aef0-42a3c142e49co%40googlegroups.com.