BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-02-2008, 11:08 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2007
Location: Cincinnati, OH
Model: 8700c
PIN: N/A
Carrier: Cingular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to hide a field?

Please Login to Remove!

RE:
net.rim.device.api.ui.component.ButtonField
(JDE 4.1)


Hi Folks,

I'd like to hide and disable a ButtonField at runtime.
I don't really see a straight forward way to do it.

In the Field, class there are methods like:
- setEditable()
- setFont()
Also, in the ButtonField class, there is this method:
- setLabel()

...So, I was hoping to find a couple of methods like:
- setVisible()
- setEnabled()

...but no such luck.

I can see a couple of work arounds to get the result I want.
For example, I can simply use the Manager.delete() method to delete my field.
And then when I need for it to be visible again, I can:
- First: Delete all the fields below (or to the right of it).
- Second: Re-add the field (using Manager.add() method).
- Third: Re-add all the fields below (or to the right of it).
However, it seems like I'm going about it the wrong way if I have to do all that. There's gotta be some more straight forward approach to this. Am I missing the big picture? (I.e. is there a completely different approach to handling GUI fields which I'm just not seeing)?.

Any ideas?

Thanks
Offline  
Old 06-02-2008, 11:56 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Have a look at Manager.insert
Offline  
Old 06-02-2008, 01:12 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2007
Location: Cincinnati, OH
Model: 8700c
PIN: N/A
Carrier: Cingular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Smile Thanks hrbuckley!

Works great. Thanks so much for your help!

(I should have seen that. )

So to delete (instead of 'hiding' and 'disabling')...

Code:
myManager.delete( myButtonField);
And then later, to re-add it in the correct position (instead of 'un-hiding' and 're-enabling') without messing with any of the other fields in that manager...

Code:
myManager.insert( myButtonField, 7); //if 7 is the position where I want it.
or...

Code:
//where whateverField is in the position right before where I want to insert myField.

myManager.insert( myButtonField, whateverField.getIndex() + 1);
Offline  
Old 08-15-2008, 04:14 AM   #4 (permalink)
New Member
 
Join Date: Aug 2008
Model: 7100T
PIN: N/A
Carrier: Don't know
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you share with me yr snippet about the stuff? I am trying to follow yr suggestion but I am unable to deal with the problem. Would u so kind to post it here? I am very pleased if u do so. Many thanks for helping me out.
Offline  
Old 08-15-2008, 12:32 PM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2007
Location: Cincinnati, OH
Model: 8700c
PIN: N/A
Carrier: Cingular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Hope this helps

Hi son_tiny,

I wrote this example for you. It shows how to:
- insert
- delete
- find position of a field

I tested it, and it seems to work fine. Should be able to just copy and paste the whole class into your project to test it.

I hope it helps

//################################################## ##########
//################################################## ##########
//################################################## ##########
Mostly what you need is between the ###'s
//################################################## ##########
//################################################## ##########
//################################################## ##########

Code:
import net.rim.device.api.ui.component.ButtonField; 
import net.rim.device.api.ui.container.FullScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener; 
//---------------------------------

class MyForm extends FullScreen
{   
    private ButtonField btn1 = new ButtonField( "Claude Debussy");
    private ButtonField btn2 = new ButtonField( "Maurice Ravel");
    private ButtonField btn3 = new ButtonField( "Dimitri Shostakovich");    
    private ButtonField btnHide = new ButtonField( "Hide");
    private ButtonField btnShow = new ButtonField( "Show");
    private ButtonField btnQuit = new ButtonField( "Quit");
  
    MyForm() 
    {   
        add( btn1);                
        add( btn2);                
        add( btn3);                
        add( btnHide);                
        add( btnShow);   
        add( btnQuit);   
        
        MyListener ml = new MyListener();

        //LISTEN TO US
        btnHide.setChangeListener( ml);
        btnShow.setChangeListener( ml);
        btnQuit.setChangeListener( ml);
    }

    //LISTENER (inner class)
    private class MyListener implements FieldChangeListener
    {   public void fieldChanged( Field field, int context)
        {   if( context != FieldChangeListener.PROGRAMMATIC) // Perform action if user changed field.
            {   
                //############################################################
                //############################################################
                //############################################################
                
                //"HIDE"
                if( field == btnHide) 
                {   
                    if( btn3.getIndex() == -1 ) { return;} //Don't try to delete it unless it's already "showing".
                
                    delete( btn3);         
                }
                //SHOW
                else if( field == btnShow) 
                {   
                    if( btn3.getIndex() != -1 ) { return;} //Don't try to add it twice.
                
                    //We'll put it right after btn2, so get position of btn2.
                    int pos = btn2.getIndex();
                    
                    insert( btn3, pos + 1);   
                }
                //############################################################
                //############################################################
                //############################################################
                
                //QUIT
                else if( field == btnQuit)
                {   System.exit( 0);   
                }
            }
        }
    }
}

Last edited by bbCincinnati : 08-15-2008 at 12:35 PM. Reason: clarification
Offline  
Old 08-17-2008, 09:29 PM   #6 (permalink)
New Member
 
Join Date: Aug 2008
Model: 7100T
PIN: N/A
Carrier: Don't know
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks my dear friend. You r such a good guy. I am really appreciated. Be cool, pal.
Offline  
Old 08-18-2008, 08:22 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Apr 2007
Location: Cincinnati, OH
Model: 8700c
PIN: N/A
Carrier: Cingular
Posts: 87
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

No problem.
Hope that helps
Offline  
Old 08-18-2008, 10:08 PM   #8 (permalink)
New Member
 
Join Date: Aug 2008
Model: 7100T
PIN: N/A
Carrier: Don't know
Posts: 8
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

It works fine. And It helps me deal with my problem. Thanks again.
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.