BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-30-2008, 08:04 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2007
Location: montreal
Model: 8100
PIN: N/A
Carrier: rogers
Posts: 70
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Help! How do I line up 3 ObjectChoiceField's in one row?

Please Login to Remove!

I tried using FlowFieldManager but it keeps putting each field on a separate line.

I did notice if I use a label it will line up right next to an ObjectChoiceField. Do I have to set a width? If so, how is this done because I can't find any witdh setting for ObjectChoiceField.

Thanks
Offline  
Old 07-30-2008, 09:37 PM   #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 you tried the HorizontalFieldManager?
Offline  
Old 07-31-2008, 07:45 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2007
Location: montreal
Model: 8100
PIN: N/A
Carrier: rogers
Posts: 70
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, but I get an exception error. Something about the width being negative.
Offline  
Old 07-31-2008, 09:14 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The width of the manager is negative? the width of a child field is negative? As you should well be able to have multople ObjectChoiceFields on a horizontal field manager, ee'll need more detail of the message or the source code itself to help out here.
Offline  
Old 07-31-2008, 09:30 AM   #5 (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

Ok, it seems that the ObjectChoiceField uses all the width available, so the first consumes the full width and there isn't any room for the second. Hence the exception. Here is a quick hack that will get 3 on a line but it isn't very satisfactory:
Code:
class MyChoiceField extends ObjectChoiceField
{
    MyChoiceField(String l, String[] c)
    {
        super(l,c);
    }
    
    protected void layout(int width, int height)
    {
        super.layout(100,height);
    }
}
Code:
...
        HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLL);
        
        String[] numbers = { "1", "2", "3" };
        String[] letters = { "A", "B", "C" };
        String[] words = {"Now", "is", "the", "time" };
        hfm.add(new MyChoiceField("1", numbers));
        hfm.add(new MyChoiceField("A", letters));
        hfm.add(new MyChoiceField("Word", words));
        add(hfm);
...
If you subclass from the HorizontalFieldManager you can probably do something better with the spacing. Some more work with the subclass of ObjectChoiceField to determine how much space it really needs would be in order as well.
Offline  
Old 07-31-2008, 12:07 PM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

a quick note on hrbuckley's approach. That works well, you can make it a little smarter by determining the maximum possible width of the field. If you're using text, use font.getAdvance() of the String[], taking the highest one. if you're using objects, you should be able to determine their width as well.
Offline  
Old 08-02-2008, 08:01 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2007
Location: montreal
Model: 8100
PIN: N/A
Carrier: rogers
Posts: 70
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to you both. That code works fine as is but as you both said, I should refine it. The maximum number of characters is 3. Some of my object choices are to 1 decimal place such a "1.5".

Just so that I understand the code better, the width of the ObjectChoiceField is set at this line?

super.layout(100,height);


If so, I need to modify the number 100, correct? And I assume that is measured in pixels.
Offline  
Old 08-02-2008, 09:00 AM   #8 (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

Yes, I just picked 100 cause it it made three fit. Bemshaswing gives good pointers to figure out dynamically (if you want to) what the value should be.
Offline  
Old 08-02-2008, 01:33 PM   #9 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2008
Model: 8310
PIN: N/A
Carrier: ATT
Posts: 17
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

We had the same problem, but with Radio Buttons. We wanted to put 5 radio buttons next to each other in the same row. Ended up extending HorizontalFieldManager. Sample code below,

Code:
public class TestScreen extends MainScreen
{
    public TestScreen()
    {

      HorizontalFieldManager mgr = new MyHorizontalFieldManager();
      RadioButtonGroup rbGroup = new RadioButtonGroup();
      for (int i = 0; i < 5; i++)
      {
          mgr.add(new RadioButtonField("", rbGroup, false));
      }
      add(mgr);

    }

}

class MyHorizontalFieldManager extends HorizontalFieldManager
{
    static int PADDING = 4;
    public MyHorizontalFieldManager()
    {
        super();
    }

    protected void sublayout(int maxWidth, int maxHeight)
    {
        int fieldcount = getFieldCount();
        Field field;
        int x = 0;
        int height = 0;
        for (int i = 0; i < fieldcount; i++)
        {
            field = getField(i);
            layoutChild(field, maxWidth, maxHeight);
            setPositionChild(field, x, 0);
            x += field.getPreferredWidth();
            //height is the maximum height of the fields
            if (height<field.getPreferredHeight()) height = field.getPreferredHeight(); 
        }
        setExtent(maxWidth, height+PADDING );
    }
}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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