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
Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

BlackBerry Field Event not Firing?

i have created a button in my Screen contructor ,but when i click on the button ,my event is not executing?can any one suggest ?

 

public myScreen(){
    _startPlayingButton = new ButtonField("Play/pause");


            _startPlayingButton.setChangeListener(new FieldChangeListener() {

                public void fieldChanged(Field field, int context) {
                    try {
                        // If the START button was pressed, begin playback
                        if (field == _startPlayingButton) {
                            // The player does not exist, we must initialize it
                            if (result) {
                                System.out.println("Result1" + result);
                                if (_player == null) {
                                    // Create a stream using the remote file.
                                    _source = new ShoutcastStream(_urlField.getText());

                                    UiApplication.getUiApplication().invokeLater(
                                            new Runnable() {
                                                public void run() {
                                                    // Update the player status
                                                    // _playStatusField.setText("Started");
                                                }
                                            });

                                    // Create and run the player's thread
                                    _playerThread = new PlayerThread();
                                    if (_playerThread != null) {
                                        _playerThread.start();
                                    } else {
                                        System.out.println("PlayerThread is null.");
                                    }
                                }
                                // The player already exists, simply resume it
                                else {
                                    _player.start();
                                }
                                result = false;

                            } else {
                                // Acquire the UI lock
                                System.out.println("Result2" + result);


                                 UiApplication.getUiApplication().invokeLater(new
                                  Runnable() { public void run() {


                                 ("Stopped"); } });
                                  }
                                 });
                                // Destroy the Player and streams
                                destroy();
                                result = true;
                            }
                        }
                        // If the STOP button was pressed:

                    } catch (IOException ioe) {
                        ioe.printStackTrace();
                        errorDialog(ioe.toString());
                    } catch (MediaException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        System.out.println(e);
                    }

                }
            });
            add(_startPlayingButton);
}
}

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BlackBerry Field Event not Firing?

please use the code tag to format your code. And remove the not relevant parts.
(How many times do we have to ask for this? Seriously, next post with full code will just be ignored).

no need to check for the startbutton, you define the changelistener only for this button, no other button can use it.

debug your code and check if the changelistener is entered.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Re: BlackBerry Field Event not Firing?

hi,

thanks for reply,i am checking for _startplayingbutton,i put a break point and checked,it is not firing,i am not able to enter  in the field?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: BlackBerry Field Event not Firing?

Can you create a simple example with just a change Listener that displays a Dialog, test if this doesn't work, if it doesn't post that code (using the code insert button) and we will have a look.  It should be about10 lines of code. 

Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Re: BlackBerry Field Event not Firing?

Hii,

       i have created a simple example,it is working good,but my code in post was not Working?

 here is the simple example i wrote:

 

public class XYXScreen extends MainScreen {


ButtonField play;
public XYXScreen(){
play=new ButtonField("play");
play.setChangeListener(new FieldChangeListener() {

public void fieldChanged(Field field, int context) {
add(new LabelField("Hiii"));

}
});
add(play);
}

}

if i click on play button ,i am able to display the text "Hiii".

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: BlackBerry Field Event not Firing?

OK, trim down your other FieldChangeListener code to match this simple FieldChangeListener and see if it works.  If it does, then add your code back in bit at a time until it breaks....