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
Posts: 172
Registered: ‎01-02-2012
My Device: 8520 curve
My Carrier: compny
Accepted Solution

How to add and delete custom button

Hi every one 

 

I am having two custom button field with different color of button called red and white.

 

And I want to add and delete both button at same place mutually.

 

I mean when I click on red button, red button has to be remove from screen and white button has to be appear,and the same when I click on white button it has to be remove and red button has to be appear. Both button has to be display at the same place.

 

 

Please any idea.....

 

Thanks.

Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: How to add and delete custom button

Hi,

You can do same by add() and delete() methods of screen and managers.
Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
Posts: 172
Registered: ‎01-02-2012
My Device: 8520 curve
My Carrier: compny

Re: How to add and delete custom button

Hi Sony

thanks for the response

 

 I am already using this method but I am getting illegal state exception...

Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: How to add and delete custom button

public void add(Field field)
throws
IllegalStateException - If the field has already been added to a manager.

public void delete(Field field)
IllegalArgumentException - If the field to be deleted does not belong to this manager.

So, do check with field.getManager() function to make it work properly..
Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to add and delete custom button

In this case you might also consider the replace function that is available in later OS's.

 

The code would simply involve, finding the button that had been clicked, using getManager to find its Manager, then invoking replace on this Manager to replace the one button with the other one.

 

However in this case I suggest that you have a two color button, and have it change its color.

Developer
Posts: 172
Registered: ‎01-02-2012
My Device: 8520 curve
My Carrier: compny

Re: How to add and delete custom button

Hi sony thanks

 

my button field declearation was wrong so it was not adding correctly.

 

any way 

 

Thanks to peter his idea also working fine.

 

Thanks all.