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: 57
Registered: ‎03-24-2009
My Device: Not Specified

Is there any easy way to show/hide screen elements?

I'm trying to set it up so when a user clicks a button (there will be several buttons), a box underneath the one clicked will show up giving them more information.  How can I show/hide elements on the screen?  I'm basically trying to achieve what setting a HTML element to "display:none;" would do.
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Is there any easy way to show/hide screen elements?

Dn't add the Field on screen till you require. add/insert the field when you need it.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 57
Registered: ‎03-24-2009
My Device: Not Specified

Re: Is there any easy way to show/hide screen elements?

The problem is that I'll need to somehow insert it after the button (it won't be the last element on the screen so I can't just add it).  Is there an insert function that allows you to insert an element at a specific spot?
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Is there any easy way to show/hide screen elements?

There is insert method available. In my previous post I have wrote add/insert considering your situation.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Is there any easy way to show/hide screen elements?

As an alternative to insert (which requires you to maintain or find an index to a Field) I tend to add a Manager to the Screen at the position in which I'm going to place Fields, and use this when I need to display Fields - I just add them to the Manager.  The Manager stays there all the time, when there is nothing to display it is empty and when I want to clear it out, I can use deleteAll. 

 

Alternatively, I will add a NullField where I want my Field to be, then I use replace and swap a Field with the NullField. 

 

These are just an extensions of the method proposed by BB Developer, that I find easier to use in some places.

New Developer
Posts: 37
Registered: ‎03-31-2009
My Device: Not Specified

Re: Is there any easy way to show/hide screen elements?

I had this same problem myself. This is what you have to do:

- Set the button and more info field.

 

ButtonField someButton = new ButtonField("Click Me"); RichTextField moreInfo = new RichTextField("More Information"):

 - Then set a listener on your button ( new ButtonListener() refers to a class you'll be creating)

 

someButton.setChangeListener(new ButtonListener());

 

 - Add the button to the screen

 

add.(someButton);

 - Now you're going to set up your listener class. How this works is anytime someone clicks that button, it will call the ButtonListener() class where you'll have logic to decide what to show, and where.

 

private class ButtonListener implements FieldChangeListener { public void fieldChanged(Field field, int context) { if(context != FieldChangeListener.PROGRAMMATIC) { if(field.equals(someButton)) { if(moreInfo.getIndex() != -1) { return; } int buttonPosition = someButton.getIndex(); insert(moreInfo, buttonPosition + 1); } } } }

 

 

 

 

 If you want to remove the info the next time the button is clicked, you can replace the return; statement with delete(moreInfo);

 

 

 

 

 

Contributor
Posts: 15
Registered: ‎01-10-2011
My Device: Not Specified

Re: Is there any easy way to show/hide screen elements?

sorry for digging it up, but i've tried the solution above and it doesn't work. when i click the button, a pop-up menu shows under the cursor and nothing happens, the textfield does not appear. does this methood need the button to call any function or what? help much appretiated.

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

Re: Is there any easy way to show/hide screen elements?

The code that inserts the field is

insert(moreInfo, buttonPosition + 1);

insert is a method available on a Manager, it is not clear from the sample which manager is being targeted by this code, so perhaps you need to direct this against a specific one. 

Contributor
Posts: 15
Registered: ‎01-10-2011
My Device: Not Specified

Re: Is there any easy way to show/hide screen elements?

Ok, worked. Now how do i hide it?

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Is there any easy way to show/hide screen elements?

delete(moreInfo);

If you look up net.rim.device.api.ui.Manager, you'll be able to find all this yourself...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!