Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Trusted Contributor
Posts: 167
Registered: ‎06-30-2011
My Device: n/a
My Carrier: Koodo
Accepted Solution

How to Create an exit button using onChangeListener

Hey its the noob again. I finally have my main screen GUI set up and it looks awesome so now I want to add some functionality to my buttons. I've been searching around but got kind of lost in how to do this, so here is some of my code. Right now I'm just trying to make the exit button (that i created) exit the application and say something. Any help?  Oh and one other question, for another button, how would I get that button to switch screens to another class (for example a Help button going to a help page)

 

Thanks again! Smiley Very HappySmiley Very Happy

 

This is what I have:

 

ButtonField exitBut = new ButtonField(" Exit ", Field.FIELD_HCENTER)

   

FieldChangeListener listenerExitBut = new FieldChangeListener() {
       
        public void fieldChanged(Field field, int context) {
           
        }
          public boolean onClose()
            {
                Dialog.alert("Bye World!");   
                System.exit(0);
                   return true;
            } 
    };
       
    exitBut.setChangeListener(listenerExitBut);
   
    fieldManagerMid.add(exitBut);

Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: How to Create an exit button using onChangeListener

you can instance  fieldChangeListener in 2 ways

1. Create inner interface of fieldChangeListener

2. implement of fieldChangeListener in your screen

 

in this void fieldChanged, you have to determine user click

public void fieldChanged(Field field, int context) {
   if (field == exitBut)
   {
      Dialog.alert("Bye World!");   
      System.exit(0);
   }    
}

 

correct me if i'm wrong

Trusted Contributor
Posts: 167
Registered: ‎06-30-2011
My Device: n/a
My Carrier: Koodo

Re: How to Create an exit button using onChangeListener

and that goes within the button's brackets right?

 

 

Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: How to Create an exit button using onChangeListener

Hmm... i prefer to implement fieldChangeListener in a mainscreen

Then for the button just set the change listener with  buttonExit.setChangeListener(this)