In totalcross, how to show a popup when I click a button inside a accordion?

Asked

Viewed 52 times

1

I have an application with Totalcross, I am using accordion and within each App I have an update button, how do I make when click the update button a popup with a message "Updated data" appears? I tried using "addPenListener" and "onEvent" but it didn’t work.

1 answer

1

It would be good for you to send us your code to understand where you went wrong when you used onEvent. Already with addPenListener, you must have confused with addPressListener.

Follow the code of creating an accordion with a Button inside, which when you click triggers a popup with a message.

public class AccordionTela extends Container {

AccordionContainer ac;
Label lb;

public AccordionTela(){
    setBackColor(Color.WHITE);
}

public void initUI(){
    ac = new AccordionContainer();
    ac.setFont(font.asBold());

    add(ac, CENTER, TOP+30, PARENTSIZE+85, PREFERRED);
    ac.setBackForeColors(0xadd8e6,Color.BLACK);
    ac.add(ac.new Caption("Legenda"), LEFT, TOP, FILL, PREFERRED);

    lb = new Label("Texto");
    ac.add(lb,LEFT,AFTER,FILL,PREFERRED);

    Button bt = new Button("botão");
    bt.setBackForeColors(Color.WHITE, Color.BLACK);
    ac.add(bt,LEFT,AFTER,PREFERRED+10,PREFERRED+10);

    bt.addPressListener(e -> {
        new MessageBox("Aviso","Dados atualizados").popup();
    });
}

}
  • Great explanation and code very elegant and clear. It seems until we work developing together ;-)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.