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
Contributor
Posts: 46
Registered: ‎07-30-2010
My Device: Bold
My Carrier: 9700
Accepted Solution

how to getWidth or getHeight inside manager?

how to get value to controlling size inside manager?

i always get 0 value for getWidth and getHeight.

 

for example i have

HorizontalFieldManager hfm = new HorizontalFieldManager();

VerticalFieldManager vfm = new VerticalFieldManager();

 

vfm.add(new LabelField("test"));

hfm.add(vfm);

add(hfm);

 

 

i want to get the width and height of vfm so i can control the sublayout and setExtent

Developer
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
My Carrier: airtel

Re: how to getWidth or getHeight inside manager?

Hi,

I hope

 vfm.getWidth();
vfm.getHeight();

 Will return the values of width and heifht of manager;

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Contributor
Posts: 46
Registered: ‎07-30-2010
My Device: Bold
My Carrier: 9700

i tried to use that but still i got 0 value is there any...

i tried to use that but still i got 0 value

is there any example for my case?

 

i want to set the width and height my manager that depends on the field inside it...

Developer
Posts: 223
Registered: ‎06-08-2010
My Device: pearl8100
My Carrier: airtel

Re: i tried to use that but still i got 0 value is there any...

Hi,

 

The way is you can extend your manager class and in sublayout()method .We can setposition of childs and setextent(width,height);

Next is adding null field(This is not preferrable).But we can set position as per our needs.

setMargin will also help you.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please press the kudos button on the left side to thank the user that helped you.
Contributor
Posts: 46
Registered: ‎07-30-2010
My Device: Bold
My Carrier: 9700

Re: i tried to use that but still i got 0 value is there any...

i want to set the set extend,sublayout method dynamicly from data(field inside the manager) width and height

is it possible?

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

Re: I tried to use that but still I got 0 value is there any...

I think you are not clear on when getWidth, getHeight and subLayout are all used and how they relate to each other.  Instead of trying to explain what you what using these method names, can you explain the effect you are trying to achieve.  Use 'layman's terms, then we won't get confused.  OK?

 

Note that until the Manager is layed out, it will not have a width or a height, so you might be in a circular situation when you are trying to calculate something that relies on something else that needs the value that you are calculating. 

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

Re: I tried to use that but still I got 0 value is there any...

To elaborate a little on what Peter has said:

 

Your Manager's sublayout() is the method that sets its width and height (along with virtual width and virtual height, along with positions of its managed fields within the Manager, etc.).  Before that, width and height are zeros.  But when is it called?

 

sublayout() is called only when BlackBerry is ready to display a screen containing the manager, overall screen layout changes (say, you tilt your touchscreen device), something that changes the displayed fields (add, delete, insert, replace on an already visible manager) happens, a field needs to update its layout and requests the whole layout to be recalculated (say, you type enough text in a TextField to make it wrap to the next line) etc.  It is a tool for the framework to let the Manager know how much room does it have and make it calculate and report its extent within those limits.

 

However, while you cannot rely on the getHeight and getWidth unless your Manager is displayed, you can have a rough estimate by using getPreferredHeight() and getPreferredWidth().  Ironically, the BB framework does not use those while laying out the screen - but all BlackBerry native Fields have some decent algorithms there, so you may find them useful.

 

Still, the main question is: what are you trying to achieve?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 46
Registered: ‎07-30-2010
My Device: Bold
My Carrier: 9700

Re: I tried to use that but still I got 0 value is there any...

i'm trying to archieve the size value (width and height) inside the manager

example :

 

 

LabelField item1 = new LabelField("test1");
LabelField item2 = new LabelField("test2");
LabelField item3 = new LabelField("test3");


HorizontalFieldManager hfm = new HorizontalFieldManager();

hfm.add(item1);
hfm.add(item2);
hfm.add(item3);

add(hfm);

 i want to know the width and height of item1,item2, and item3

so i can set the sublayout

 

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

Re: I tried to use that but still I got 0 value is there any...

I recommend that you review these two videos:

 

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

 

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-the-Screen/ta-p/446745

 

Then have a look at this:

 

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

 

The trick is what to do at this line:

    y += ...;

Because you have asked the child to layout itself here:

    layoutChild(field, width, height); //lay out the field
it should know how big it wants to be.  So you can ask it how big it is

field.getHeight()();

field.getWidth();

 

Does that help?

Contributor
Posts: 46
Registered: ‎07-30-2010
My Device: Bold
My Carrier: 9700

Re: I tried to use that but still I got 0 value is there any...

here is my case

 

i set the header and footer setExtent height = display.getHeight( )/5
and the body setExtent height = display.getHeight( )*3/5

so i will have a fixed layout.

 

but i have a problem with my list field (my list field not static/fixed, i got it from database, so i can't set the setExtent)

 

everytime scroll it down, at the end of line all my field and my body become blank (white)

 

 

i've tried by set the setExtent to a certain numbers for example 500

its work but if only my list field (data) is static.

 

 

 

 

sorry, i'm really bad explaining it