codenameone - 如何在对按钮 Codenameone 执行特定操作后重新加载整个表单

标签 codenameone

当我从购物车中删除产品时,我想刷新我的表格我尝试了所有方法但没有用,有什么办法吗?

我的 Cart 类显示了我的购物车中的产品以及当我从购物车中删除产品时我想要的位置我想刷新整个表单但不知道该怎么做我几乎没有尝试过所有方法但是还是做不到

public class Cart {
  Form f;

  public Cart() throws IOException {
      f = new Form("cart",BoxLayout.y());

      Button b = new Button("back");
      b.addActionListener(e->{
         AfficherProduits sp;
          try {
              sp = new AfficherProduits();
              sp.getF().show();
          } catch (IOException ex) {
              System.out.println("ERREUR DANS RETOUR LISTE PRODUITS ");
          }
      });
      f.add(b);

      //**********************************instanciation du panier********************************************************
      Panier panier=Panier.getInstance();


      //********************************Parcourir le panier**************************************************************
       ComponentGroup cg = new ComponentGroup();
      for (Lignedecommande c : panier.p)
      {
          Container c4 =new Container(BoxLayout.x());
          Container c3 =new Container(BoxLayout.y());
          Container c2=new Container(BoxLayout.x());
          Container c1=new Container(BoxLayout.y());
          Container c5=new Container(BoxLayout.y());

      //***************************les elements du containers************************************************************
          ImageViewer iv=new ImageViewer();
          iv.setImage(Image.createImage("/"+ c.getProduct().getImage()).scaled(80, 80));

          Button bt=new Button("X");

          bt.addActionListener(e->{
             panier.removeLine(c);
             //ShowListProduct sp=new ShowListProduct();
             //sp.getF().show();
             f.removeComponent(cg);
             f.refreshTheme();
          });
          //********************les boutons de modif quantite******************************************
          Button b1=new Button("+");
          Button b2=new Button("-");
          bt.getStyle().setPadding(0,0,0,0);

          //*****************************mettre le bouton X au milieu****************************************************
          Label lb1=new Label(".");
          Label lb2=new Label(".");
          lb1.setVisible(false);
          lb2.setVisible(false);
          c1.add(lb1);
          c1.add(bt);
          c1.add(lb2);

          c5.add(b1);
          c5.add(b2);

          c4.add(c1);
          c4.add(iv);

          c2.add(new Label(Integer.toString(c.getQuantite())));
          c2.add(c5);
          //c2.add(b2);

          //c3.add(new SpanLabel(c.getProduct().getName()));
          c3.add(c2);


          c4.add(c3);
          c4.add(new Label("$"+Float.toString(c.getProduct().getPrix()*c.getQuantite())));

          cg.add(c4);
      }
      f.add(cg);
  }

  public Form getF() {
      return f;
  }

  public void setF(Form f) {
      this.f = f;
  }
}

还有我如何调用这个页面来查看我的购物车

  h = new AfficherProduits();
  h.getF().show();

最佳答案

不要重新加载。重新创建和显示。

将构造函数中的所有代码移至名为 createCartForm() 的方法。然后构造函数会做:

f = createCartForm();

重新加载会变成:

setF(h.createCartForm());
getCurrentForm().setTransitionOut(CommonTransitions.createEmpty());
h.getF().show();

我用一个新实例替换了表单并删除了默认转换,这样替换就不会被动画化了。

关于codenameone - 如何在对按钮 Codenameone 执行特定操作后重新加载整个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49981728/

相关文章:

java - 我是否需要关闭代号一中的屏幕(以防止内存泄漏)?

java - 我可以在 Dialog.show 中以代号 One 插入图像吗

java - 从 CodeName One for Java 中的 TextField 获取文本

Android 构建始终创建调试 apk

CodenameOne:与 3.x 版本相比,DialogBody 在 CodenameOne 4.x 中留下了太多空间

codenameone - iPhone 6 : InteractionDiaog appears too far down; content hidden

java - 列出 codenameone 中的渲染器问题

ios - 代号一 - 无法从真实设备上的套接字读取

codenameone - 如何防止虚拟键盘在 JavaSE 构建上显示

java - 如何在没有sqlite数据库的情况下使用代号一和eclipse保存/加载表内容