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
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009

Buttonfield issue.

Hi,

 

 

I have a screen which has a button and objectlistfield.

 

I have implemented navigationClick and the objectlistfield responds to that event.

 

But the button press also responds to the same navigationClick  which objectlistfield responds to.

 

I have the following code for the button:

 

FieldChangeListener listener = new FieldChangeListener() {
             public void fieldChanged(Field field, int context) {
             ButtonField buttonField = (ButtonField) field;
             System.out.println("Button pressed: " + buttonField.getLabel());
             getSearchResults(searchCity.getText());
         }
         };

 

in the constructor of the class, which does not get called when i click the button.

 

Every time i click thebutton,  navigationclick gets invoked and as a result I am not able to do any action on button click / press

  

kindly guide me as to what should I do?

 

 

Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Buttonfield issue.

use the CONSUME_CLICK style when creating the button.
don't forget to add the changelistener to the button.
----------------------------------------------------------
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
Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009

Re: Buttonfield issue.

thanks Simon,

 

it didnt work, still the navigationClick gets invoked.

Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Buttonfield issue.

i have quite some of these buttons. please show the relevant parts of your code, CONSUME_CLICK works like a charm.
----------------------------------------------------------
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
Please use plain text.
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009

Re: Buttonfield issue.

public class PowNowHomeScreen extends MainScreen { // text field used for searching private BasicEditField searchCity; // button private ButtonField search; // registering listener with the button FieldChangeListener listener = new FieldChangeListener() { public void fieldChanged(Field field, int context) { ButtonField buttonField = (ButtonField) field; System.out.println("Button pressed: " + buttonField.getLabel()); // method to be invoked when button is pressed. getSearchResults(searchCity.getText()); } }; // Constructor of the class PowNowHomeScreen(double lat, double lon, String cityName) { // search field search = new ButtonField("Search", ButtonField.CONSUME_CLICK); search.setChangeListener(listener); // object of Object list field menu = new MyObjectListField(); mainMenuItems = new String[]{mnuSearchTitles}; // object list field items - String menu.set(mainMenuItems); this.add(search); } // object list field class private class MyObjectListField extends ObjectListField { } // overridden navigation click protected boolean navigationClick(int status, int time) { // code for click on objectlistfield } } // End of PowNowHomeScreen Class

 

    The snippet of the code is inserted above. The problem is that for button click fieldchanged is not invoked but navigationclick is invoked

, navigationclick has code for click on objectlistfield.

 

kindly advise as I am totally lost and I have to finish the functionality today EOD.

 

 

  

Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Buttonfield issue.

i don't see an error in your code,
search = new ButtonField("Search", ButtonField.CONSUME_CLICK);
should create a ButtonField with the correct behaviour.
you can overwrite navigationclick to return true in your ButtonField, but normally the style-flag should do that for you.
----------------------------------------------------------
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
Please use plain text.