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

New Developer
Posts: 8
Registered: ‎09-18-2009
My Device: Not Specified
Accepted Solution

Variable # of ButtonFields and Methods

Hello all, I have a question that I can't solve with my current knowledge, and couldn't find an alternate solution on the internet. So here it goes:


I want to add variable number of buttonfields (depending on the data coming from the database). But the problem is how to fire the clicking event of the buttons ? There is the sample code I've written:



 ButtonField mybutton = new ButtonField(ans.getText(), FIELD_HCENTER | ButtonField.CONSUME_CLICK)


                    protected boolean trackwheelClick(int status, int time)


                        System.out.println(nameID.toString()+"   "+ stateID.toString());

                        return true ;






please don't be worried about any variable names etc, the only problem is I can't see  nameID and stateID on the console. so somehow the buttons I created in this loop don't do their events. What should I do ?

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

Re: Variable # of ButtonFields and Methods

if you create the button with consume_click navigationclick is not executed. you can do either one, not both.
if you return true in your navigationclick the button consumes it as well.
another option is a fielchangelistener (with consume_click)

there are several possible approaches to identify your buttons if you use a fieldchangelistener:
the easiest would be to store all added buttons in a data structure like a vector. you can decide which action to take by index.
you could also create your own class that extends button and features an identifier, similar to html buttons that have both a label and an (invisible) command.
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
New Developer
Posts: 8
Registered: ‎09-18-2009
My Device: Not Specified

Re: Variable # of ButtonFields and Methods

thanks, implementing the field change listener and storing the buttonfields in a vector solved the problem. Although this is the first time I really look for the addressing in the C++, since you can't pass the reference of an object in java. Thanks anyways, I get it working now.