如何在对按钮Codenameone执行某些操作后重新加载整个表单
当我从购物车中删除产品时,我想刷新我的表单。我尝试了所有方法,但都没有成功。有办法吗 有一个我的购物车类,它显示我购物车中的产品以及我想要的位置。当我从购物车中删除产品时,我想刷新整个表单,但不知道如何执行。我几乎尝试了所有方法,但仍然无法完成如何在对按钮Codenameone执行某些操作后重新加载整个表单,codenameone,Codenameone,当我从购物车中删除产品时,我想刷新我的表单。我尝试了所有方法,但都没有成功。有办法吗 有一个我的购物车类,它显示我购物车中的产品以及我想要的位置。当我从购物车中删除产品时,我想刷新整个表单,但不知道如何执行。我几乎尝试了所有方法,但仍然无法完成 public class Cart { Form f; public Cart() throws IOException { f = new Form("cart",BoxLayout.y()); Button b =
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();
我用一个新实例替换表单,并删除默认的转换,这样替换就不会被设置动画