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
Developer
Posts: 19,629
Registered: ‎07-14-2008
My Device: Not Specified

Re: Focusable HorizontalFieldManager

I'm interested to see what you are doing in the 'HorizontalSheet'.

 

The main reasons that I like ListField over methods that involve populating the Screen with Fields, is that it is dynamic (the size can change easily) and it can cope with large numbers of items.  For small number of items ( < 20 say ), then the approach of adding a component for each sheet is probably manageable.

Developer
Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

Re: Focusable HorizontalFieldManager

this is my cusom  horizontal sheet

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Max; import net.rim.device.api.system.Characters; import net.rim.device.api.system.Display; import net.rim.device.api.system.KeyListener; import net.rim.device.api.system.KeypadListener; import net.rim.device.api.ui.Color; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.FocusChangeListener; import net.rim.device.api.ui.Font; import net.rim.device.api.ui.FontFamily; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.component.SeparatorField; import net.rim.device.api.ui.container.HorizontalFieldManager; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.container.VerticalFieldManager; /** * * @author rakesh */ public class HorizontalSheet extends VerticalFieldManager implements FocusChangeListener { DateField d0; Desp des0; Amt a0; Font fnt; HorizontalFieldManager ms; SeparatorField sep,sep1; public static int Selected=Color.GREEN; public static int UnSelected=Color.YELLOW; public static int base=UnSelected; int pcolor=Color.BLUE; String title1,title2,title3; HorizontalSheet(boolean b,String s0,String s1,String s2) { if(b) { title1=s0; title2=s1; title3=s2; fnt = this.getFont().derive(FontFamily.SCALABLE_FONT, 14); ms=new HorizontalFieldManager(); ms.setFont(fnt); d0=new DateField(title1,true); d0.setFocusListener(this); ms.add(d0); sep=new SeparatorField(SeparatorField.LINE_VERTICAL) { protected void layout( int maxWidth, int maxHeight ) { int width = Display.getWidth(); int height = 25; //height of the manager super.layout(3, 15); } }; ms.add(sep); des0=new Desp(title2,true); des0.setFocusListener(this); ms.add(des0); sep1=new SeparatorField(SeparatorField.LINE_VERTICAL) { protected void layout( int maxWidth, int maxHeight ) { int width = Display.getWidth(); int height = 25; //height of the manager super.layout(3, 15); } }; ms.add(sep1); a0=new Amt(title3,true); a0.setFocusListener(this); ms.add(a0); this.add(ms); add(new SeparatorField()); this.invalidate(); } // add(new LabelField("True")); } HorizontalSheet(String s0,String s1,String s2) { fnt = this.getFont().derive(FontFamily.UNKNOWN_FONT, 12); ms=new HorizontalFieldManager(); ms.setFont(fnt); d0=new DateField(s0); d0.setFocusListener(this); ms.add(d0); sep=new SeparatorField(SeparatorField.LINE_VERTICAL) { protected void layout( int maxWidth, int maxHeight ) { int width = Display.getWidth(); int height = 25; //height of the manager super.layout(3, 15); } }; ms.add(sep); des0=new Desp(s1); des0.setFocusListener(this); ms.add(des0); sep1=new SeparatorField(SeparatorField.LINE_VERTICAL) { protected void layout( int maxWidth, int maxHeight ) { int width = Display.getWidth(); int height = 25; //height of the manager super.layout(3, 15); } }; ms.add(sep1); a0=new Amt(s2); a0.setFocusListener(this); ms.add(a0); this.add(ms); add(new SeparatorField()); this.invalidate(); //VerticalFieldManager vm=new VerticalFieldManager(); } public boolean keyChar( char key, int status, int time ) { if ( key == Characters.ENTER ) { add(new LabelField(this.getClass().getName())); } return false; } public void focusChanged(Field arg0, int arg1) { if(arg0 instanceof Desp) { Desp dsg=(Desp)arg0; if(arg1==FOCUS_GAINED) { OverallFocus(); dsg.idFocus(pcolor); } if(arg1==FOCUS_LOST) { OverallUnFocus(); } this.invalidate(); } if(arg0 instanceof Amt) { Amt am=(Amt)arg0; if(arg1==FOCUS_GAINED) { OverallFocus(); am.idFocus(pcolor); } if(arg1==FOCUS_LOST) { OverallUnFocus(); } this.invalidate(); } } public void OverallFocus( ) { d0.Focus(); des0.Focus(); a0.Focus(); } public void OverallUnFocus() { d0.UnFocus(); des0.UnFocus(); a0.UnFocus(); } }

 

check this out,tell if ther are any modifications required,i used custom datefield,date,and amtfield

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Max; import net.rim.device.api.system.Display; import net.rim.device.api.ui.Color; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.component.LabelField; /** * * @author rakesh */ class DateField extends LabelField { int sd,br,lr; DateField(String s) { super(s,LabelField.LEFT); br=Color.YELLOW; lr=Color.GREEN; } DateField(String s,boolean b) { super(s,LabelField.LEFT); br=Color.BLACK;; lr=Color.WHITE; } public int getPreferredWidth() { sd=Display.getWidth()*2/10; return Display.getWidth()*2/10; } public int getPreferredHeight() { return 15; } public void Focus() { HorizontalField.base=HorizontalField.Selected; br=HorizontalField.base; lr=Color.BLUE; this.invalidate(); } public void UnFocus() { HorizontalField.base=HorizontalField.UnSelected; br=HorizontalField.base; lr=Color.GREEN; this.invalidate(); } public void idFocus(int s) { br=s; lr=Color.BLACK; } public void LabelBackgroundColor(int c) { br=c; } public void LabelColor(int c1) { lr=c1; } public void paint(Graphics g) { g.setColor(br); g.fillRect(0,0, sd,this.getPreferredHeight()); g.setColor(lr); super.paint(g); } }

 

similar i have done for amt and desp

 

reply me,thanks

New Developer
Posts: 19
Registered: ‎04-09-2009
My Device: Not Specified

Re: Focusable HorizontalFieldManager

When you say you need to focus on the entire row, what exactly do you mean by that?  Is not the CURSOR going to be in SOME FIELD? 

 

I -suspect- what you mean is that you want to indicate somehow that the row is selected.  When we do that, we use a custom field manager and override the paint and subpaint methods, so that the ROW that we're on we set the background color to our "selected color" and the rows we are NOT on we set the color to our "not selected color"  using an override of subpaint.  (being careful for speed reasons to not bother to call subpaint on fields which are not visible) :-) 

 

You might want to look at GridFieldManager instead of your combination of Vertical and Horizontal managers.  GridFieldManager overrides navagation movement so that moving around the grid is "natural."

 

see  http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=40760&query.id=29... 

 

 

Developer
Posts: 39
Registered: ‎10-19-2010
My Device: drova 9700

Re: Focusable HorizontalFieldManager

OMG why all guys sayd about ListField. IF we want  focused in HorizontalFieldManager, so if anyone know how to do it.. maybe he help ??

Im reading this forum many times.But here many stupid words... 

How to focused in horizontalfieldmanager if  its in array.   ?

regards, Peter.

Contributor
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: Focusable HorizontalFieldManager

I would love to know that too!

Didn't anyone try it with an array of HFM?