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
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified
Accepted Solution

how can i show multiple row using Horizonatal and vertical field manager

hello

 

can anybody tell me how i can layout my screen using HorizonatalFieldManager and VerticalFieldManager.

 

 

i want to display image and text like below way:

 

image1  text1

image2  text2

image3  text3

 

i try more time but it can throw unacaught exception,

can u give me any example like it.

 

i also store default image where url not contain any image

 

it work with FlowField but it show like below:

image1  text1      image2  text2

image3  text3      image4  text4

 

 

i dont want this ,i like to show such as first mention.

 

 

now i work in bb jde 4.6 and i want support it 4.6 and later

 

 

 

Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

Re: how can i show multiple row using Horizonatal and vertical field manager

It is very easy task.

You have to take one Vertical FieldManager then insert that VErticalFieldManager in a Screen.

Then take  3 Horizontal fieldManager one for each row so you can create 3 rows.

Then add  Image1 and text1 in horizontalfieldManager1 like that for second and third row then add that 3 horizontalFields in verticalField manager..

Lathiya Himanshu
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: how can i show multiple row using Horizonatal and vertical field manager

i take images and text dynamically from url and there are ten images and texts,

 

i try like this,for example

 

for(i=0;i<titleList.getLength();i++)

{

hfm.add(new Label(data));

hfm.add(bf);

vfm.add(hfm);

}

 

add(vfm);

 

 

it's not real code ,but logic like it.

 

it show me uncaught exception.

 

here hfm ->horizonal

and vfm->vertical

bf->bitmapfield

data->text

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

Re: how can i show multiple row using Horizonatal and vertical field manager

1) Are you getting IllegalStateException? This is normal if you are trying to manipulate anything on the Screen stack from a non-event thread. If it is another exception, post the details here.

2) For your layout you need a separate HFM for each text-image pair. Like this:

 

VerticalFieldManager vfm = new VerticalFieldManager(VERTICAL_SCROLL ...);
for (i = 0; i < length; ++i) {
  HorizontalFieldManager hfm = new HorizontalFieldManager();
  hfm.add(new Label(text[i]));
  hfm.add(new BitmapField(image[i]));
  vfm.add(hfm);
}
add(vfm);

 If you are adding all this to a MainScreen with "no arguments" constructor (it has VERTICAL_SCROLL enabled by default), you can skip vfm and add your HFMs directly to the screen.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: how can i show multiple row using Horizonatal and vertical field manager

thank u very much,

i solve my problem according ur guidence.

actually i do not declare Horizontalfield every time,

i just use globaly it .

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

Re: how can i show multiple row using Horizonatal and vertical field manager

The point is not to declare HFM every time (even though I did that in the loop) - the point is to create a new one for each "row" (new HorizontalFieldManager()).

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: how can i show multiple row using Horizonatal and vertical field manager

thanks,

i have one problem about to put seperator betwwen two row.

and also require to put space between image and text horizontally

example;

------------------

image1   text1

--------------------

image2   text2

-------------------

 

when i add separatorField in vertaiacalfieldmanager it show me error like,

u don't  add  void property in verticalField manager.

 

help me please. 

Developer
Posts: 122
Registered: ‎09-15-2010
My Device: BB - 9800

Re: how can i show multiple row using Horizonatal and vertical field manager

Hi there, 

 

       Inorder to display a separator between the rows use SepatatorFiled in the ' for ' loop and 

for maintaining distance between the fields in rows use setMargin and setPadding methods.

 

       May be below code 'll b helpful.

 

 

VerticalFieldManager _vfm = new VerticalFieldManager(VERTICAL_SCROLL);
for (i = 0; i < length; ++i) {
  HorizontalFieldManager _hfm = new HorizontalFieldManager();
  _hfm.add(new LabelField(text[i]));
  _hfm.add(new BitmapField(image[i]));
  _hfm.setPadding(9,9,9,9);
  _hfm.setMargin(9,9,9,9);
  vfm.add(_hfm);
  vfm.add(new SeparatorField());
}
add(vfm);

 

use setPadding and setMarging method with fields and managers effectively inorder to achieve ur 

requirements.

 

regards,

Saran.

 

       Give kudos if this post is helpful..........Smiley Happy

 

 

Highlighted
Developer
Posts: 34
Registered: ‎09-24-2009
My Device: Not Specified

Re: how can i show multiple row using Horizonatal and vertical field manager

For Space between LabelField & Image, you can use either setPadding() method or add a LabelField with text as '   '(some spaces) .

 

And for Separators each time you have to create new instance of SeparatorField and add it to the VerticalFieldManager.

 

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: how can i show multiple row using Horizonatal and vertical field manager

thanks it work.