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
New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified
Accepted Solution

How to Customise a HorizontalFieldManager

Hi, i have a piece of code which actually creates a Heading to a Screen and it doesnt scroll along with the Contents of Screen.......i want to constomise this piece of cord that is i want to place this code in seperate class and when i want to create a Heading to a Screen then i want to call this class............Actually this heading is a HorizontalFieldManager..........so i am unable to keep this seperate class as i dont know wht class needs to be extended and what all code needs to be kept in the respective constructor ................. i have paste below the code which has to customised............. it is Horizontalfieldmanager which creates a Heading to the screen which doesnt scroll.........

 

final int imageWidth = demoText.getPreferredWidth(); final int imageHeight = demoText.getPreferredHeight(); int dataTransparent[] = new int[imageWidth * imageHeight]; final Bitmap transparentImage = new Bitmap(imageWidth, imageHeight); transparentImage.setARGB(dataTransparent, 0, imageWidth, 0, 0, imageWidth, imageHeight); headerManager = new HorizontalFieldManager() { protected void paintBackground(Graphics graphics) { graphics.drawBitmap(0,0,imageWidth, imageHeight, transparentImage,0,0); } };

kindly help in this regards...............

Thank you....

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager

actually my task was to create class which extends a Screen class...........and my screen draws a background image ...........and has a heading which should not be scrolled and has lot of lines of contents which has to be scrolled down.....THIS TASK I POSTED IN FORUM EARLIER AND IT WAS SOLVED...........THE SOLUTION THAT THEY PROVIDED WAS THE ABOVE CODE WHICH DRAWS A SERATE HORIZONTALFILELDMANAGER AS HEADING, AND THEY HAVE MADE IT AS TRANSPERANT SO THAT THE BACKGROUND IMAGE CAN BE VIEW...........BUT MY REQUIREMENT IS I WANT TO KEEP THIS PIECE OF CODE WHICH DRAWS THE HEADING IN SOME A SEPERATE CLASS SO THAT IT TIME ADDING ITEMS IN THE HEADING I CAN CREATE A OBJECT OF THIS CLASS AND CREATE A SEPERATRE HEADING........I AM UNABLE  TO KEEP THIS CODE IN SEPERATE CODE AS I DONT KNOW HOW TO DO IT AND DONT KNOW WHICH CLASS HAS TO BE EXTENDED AND WHAT CODE GOES INTO THE CONSTRUCTOR AND WHEN THE paintBackground() method id called........

final int imageWidth = demoText.getPreferredWidth(); final int imageHeight = demoText.getPreferredHeight(); int dataTransparent[] = new int[imageWidth * imageHeight]; final Bitmap transparentImage = new Bitmap(imageWidth, imageHeight); transparentImage.setARGB(dataTransparent, 0, imageWidth, 0, 0, imageWidth, imageHeight); headerManager = new HorizontalFieldManager() { protected void paintBackground(Graphics graphics) { graphics.drawBitmap(0,0,imageWidth, imageHeight, transparentImage,0,0); } };

Kindly pls help.........

Highlighted
New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

How to Customise a HorizontalFieldManager

pls help me query is mentioned above.......

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager

You can create a Class extending HorizontalFieldManager. Something like:

 

public class HeaderManager extends HorizontalFieldManager { int imageWidth; int imageHeight; int dataTransparent[]; Bitmap transparentImage; public HeaderManager(String headerText) { super(); LabelField text = new LabelField(headerText, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); imageWidth = text.getPreferredWidth(); imageHeight = text.getPreferredHeight(); dataTransparent = new int[imageWidth * imageHeight]; transparentImage = new Bitmap(imageWidth, imageHeight); transparentImage.setARGB(dataTransparent, 0, imageWidth, 0, 0, imageWidth, imageHeight); this.add(text); } protected void paintBackground(Graphics graphics) { graphics.drawBitmap(0,0,imageWidth,imageHeight,transparentImage,0,0); } }

 

And from your screen call:

 

HeaderManager headerManager = new HeaderManager("Hello World Demo"); this.add(headerManager);

 

Regards

Bikas

 

 

 

 

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager


Hi Bikas,
 Its working great, Thank for ur Valuable solution.............well in HeaderManager class instead of a String can i add an ObjectChoiceField and make it as center................I mean in Headermanager i want a ObjectChoiceField in the Center i.e a  non Scrollable Heading with a ObjectChoiceField........................Can this Happen..........Again Thanks for ur Solution,,,,,,,,,,,,
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager

For making the LabelField center try this:

 

LabelField text = new LabelField(headerText, LabelField.ELLIPSIS | DrawStyle.HCENTER | Field.FIELD_HCENTER | Field.USE_ALL_WIDTH);

 

Regards

Bikas

 

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager

For making ObejctChoiceField in the center try something like this.

Just a rough idea. Not an optimal solution.

 

public HeaderManager(String choices[]) { super(); ObjectChoiceField text = new ObjectChoiceField("", choices, 0) { protected void layout( int w, int h) { int width = Display.getWidth() /2; super.layout( width, this.getPreferredHeight()); setExtent( width, this.getPreferredHeight()); } }; //.......... //.......... }

 

And from you screen use:

 

String choices[] = {"one", "two", "three"}; final HeaderManager headerManager = new HeaderManager(choices); this.add(headerManager);

 

Regards

Bikas

 

 

 

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager

 

     Bikas, Thank u it has come to center........

 

    -Well how to add an ObjectchoiceField in this HeaderManager..................

    -Can i call this Header manager 3 times  one after another in order to have three Horizontal Field's which doestnt scroll and  when     i    first call headermanager class i display a labelField and second when i call i place a ObjectchoiceField and third i place a button....can this happen all these fields which add should be non scrollable.....

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager

This HeaderManager class is a simple horizontalFieldManager that have a transparent background and

its height is depends on the added field in it.

And you have to control nonscrollable issue  from your screen class.

 

Can you explain exactly what are you trying to get.

 

Regards

Bikas

New Developer
Posts: 122
Registered: ‎07-28-2009
My Device: Not Specified

Re: How to Customise a HorizontalFieldManager

Sure Bikas i shall explain in Detail..........

 

See i have 2 Screen in Total........All the Screens Extend Screen Class...........I navigate from one Screen to Another......That is Now i am Screen_1 . In Screen_1 if i press a Button i go Screen_2.......All this navigation is done no problem......But My Exact Problem are in Screens headings.....I will explain u one by one Screen.

 

In Screen_1 :

Screen_1 has Top Most heading(HeaderManager) which is NonScrollable and it has a LabelField this is Done, means able to display the labelField.....Now Below This Label i want  a ButtonField(say Logout Button)  Which has to be Left alligned to the screen...this button also should NOT be scrolled......This is how my First Screen is.........And i Screen_1 Contents when i press a Button i go to SCreen_2..this navigation(Going to SCree_2) i have done it.......

 

In Screen_2:

In Screen_2 has also has a Top most Heading(Header Manager) which is label which is center aligned this is Done, and Below this Label Field I have anothe Label Field Which is Left Aligned ......Now below  this label  i want  a to place ObjectChoiceField as center aligned.....in This screen all these Three (Label Field Center aligned, LabelFiel LeftAligned, and ObejctChoiceField  Center aligned Center) as NON Scrollable........

 

So if I have two class Screen_1 & Screne_2 and another class i have Customise class called  HeaderManager........In Screen_1 when i want to create the heading then i call HeaderManager class and draw diaplay the heading in center........ and next agin i call this HeaderManager to display a Button(Logout Button) below this Heading as Left Aligned............So i think u got it in order to draw this NON SCrollable Headings(LabelField) and Display Button Field and Objectchoice fields i want to call this HeaderManager class when required........

 

Thanking you.........