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
sudhirispl
Posts: 17
Registered: ‎08-18-2008
My Device: Not Specified

Problem while moving focus horizontally in GridControl

Hello All,
How To - Create a screen with stationary headings
DB-00510
http://tinyurl.com/5nxx6u
I want to develop a GridControl in BB. So my grid control will take numer of rows and column as parameter, and
it will draw the Grid(Table) accordingly. To develop the Grid Control I refered this Knowledge Base Article.
So, now I am able to show the Grid by using above KB. But Now my problem is while moving from one field to other field,
the focus doesn't move accordingly. I mean as per above KB, when I try to move focus from Data 0,0 to Data 1,0 the focus
moves to the field which is at bottom bottom of the Column 1. When I move my trackwheel vertically it works fine.
But problem is while moving focus horizontally.
What should I do in my code to move focus horizontally?.
I tried to use moveFocus() method but it doesn't worked. So, experts please guide me here.

thanks

Please use plain text.
Administrator
MSohm
Posts: 14,379
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Problem while moving focus horizontally in GridControl

You can add custom focus behaviour by overriding the navigationMovement method of the screen and calling setFocus from there, applying focus to the desired field.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
sudhirispl
Posts: 17
Registered: ‎08-18-2008
My Device: Not Specified

Re: Problem while moving focus horizontally in GridControl

Hello Mark and all,

Thanks for your reply, I tried to use setFocus() methos in navigationMovement() as you mentioned. But, that field is not taking focus.

I just try to explain the scenario:

So, I just want to display the Grid of say 5 rows and 5 columns.

For, that I am using 5 verticalfield managers(For columns), and each verticalfieldManager have 5 labelFields(For rows).So, it is displayed properly.

My problem is while when I move focus horizontally, it works properly in vertical direction(default behaviour).

So, my grid will look like this:

 

 00   01   02   03   04

 10   11   12   13   14

 20   21   22   23   24

 30   31   32   33   34

 40   41   42   43   44

 

So, when the focus is on say labelfield "10" and I move the trackwheel horizontally, then because of default behaviour field "41" takes the focus.

So, I used the setFocus() method as mark suggests.

So, when I move focus from field "10", I am able to get the field at the horizontal right which is "11", so I am using setFocus() method on field "11". but, instead of field "11", focus goes to field "02".

I am not able to able to figure out the problem here. Am, I missing something obvious here? 

 

Thanks, waiting for your replys...

 

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,379
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Problem while moving focus horizontally in GridControl

[ Edited ]
Are you returning true in the navigationMovement method to tell the system you have consumed the trackball roll?  It sounds like you may not be, so that the roll is being processed twice (once by your code and once by the BlackBerry).
Message Edited by MSohm on 08-26-2008 02:22 PM
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
sudhirispl
Posts: 17
Registered: ‎08-18-2008
My Device: Not Specified

Re: Problem while moving focus horizontally in GridControl

[ Edited ]

Hello All,

I just try to clarify my point here,

As, I am developing the Grid Control, it is having one Horizontalmanager for Header display,
And the same number of vertical manager as the number of columns in the Grid. So, for, 5 columns I will have 5
vertical manager and I am adding these managers to a Horizontal manager, and adding this Horizontal manager to
a main Vertical Manager. And finally adding Header Manager and main Vertical Manager to screen.

So, when my screen contain only one Field i.e. Grid Control it is working OK. And vertical scrolling working properly.
But, when my screen contains some other fields labelField, editfields at top.
And below that if I placed my Grid Control, let's say at middle of screen, first time it looks OK, but when I try to
scroll it vertically, eventually it takes the area of entire screen.
I just dont want this to happen. So, If I am placing my Grid Control at center of screen then when I scroll it vertically
it should go only till height of screen and its base position should not change, i.e. it should remain at center of screen.

I am using sublayout method here to do this task. But, not able to got it working.
Can anyone please help me here.

Thanks...

Message Edited by sudhirispl on 09-01-2008 02:31 AM
Please use plain text.
New Developer
sudhirispl
Posts: 17
Registered: ‎08-18-2008
My Device: Not Specified

Re: Problem while moving focus horizontally in GridControl

Hello All,

      Please give me any suggession for above issue. Thanks in advance

 

Thanks

Please use plain text.
Administrator
MSohm
Posts: 14,379
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Problem while moving focus horizontally in GridControl

What you describe should be possible by overriding navigationMovement and calling setFocus on the field you wish to scroll to.

 

Can you provide some sample code of your implementation?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
sudhirispl
Posts: 17
Registered: ‎08-18-2008
My Device: Not Specified

Re: Problem while moving focus horizontally in GridControl

[ Edited ]

  Hi Mark and All,

Thanks for Reply

class ListScreen extends MainScreen{
    VerticalFieldManager controlManager  = new VerticalFieldManager(NO_VERTICAL_SCROLL );
    HorizontalFieldManager  verticalControlManager = new HorizontalFieldManager(Field.FIELD_HCENTER | HORIZONTAL_SCROLL);
    Graphics graphics = getGraphics();
    public ListScreen(){
        String header[] = {"Name","Trip Number","City","Amount"};
        String data [][] = {{"Hemant kumar jain","25000","Nagpur","500"},
                            {"Sudhir jain","5000","Bhopal","500"},
                            {"Manoj","2500000000","Bhopal","500"},
                            {"Avik","25000","Bhopal pune nagpur","500"},
                            {"Avikhh","25000","Bhopal","500"},
                            {"Avikhh","25000","Bhopal","500"},
                            {"Samar","25000","Bhopal","500"}
                            };
       
        controlManager.add(new LabelField(" "));
        controlManager.add(new LabelField(" "));
        controlManager.add(new LabelField(" "));
        controlManager.add(new LabelField(" "));
        controlManager.add(new LabelField(" "));
        controlManager.add(new LabelField("                      Hello World!!"));
        GridControl grid = new GridControl(7, 4,105,graphics,data,header);
        controlManager.add(grid.getControlHeading());
        controlManager.add(grid.getControl());
        verticalControlManager.add(controlManager);
        add(verticalControlManager);
    }
   
}

Message Edited by sudhirispl on 09-04-2008 04:14 AM
Please use plain text.
New Developer
sudhirispl
Posts: 17
Registered: ‎08-18-2008
My Device: Not Specified

Re: Problem while moving focus horizontally in GridControl

public class GridControl  extends HorizontalFieldManager{
   
    public GridControl(int row, int col,int colWidth ,Graphics graphics,String [][]data,String[] headerdata){
        super(MainScreen.NO_VERTICAL_SCROLL | MainScreen.HORIZONTAL_SCROLL);
        graphics = graphics;
        fnt = graphics.getFont();
        lblField = new LabelField[row][col];
        sbData = new StringBuffer();
        LabelField headings[] = new LabelField[col];
        noOfCols = col;
        noOfRows = row;
        gridData = data;
        tempGridData = data;
        headerData = headerdata;
        columnWidth = colWidth;
        widthVFM = columnWidth*noOfCols;
        columnHeadingHolder = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL
                | HorizontalFieldManager.NO_VERTICAL_SCROLL | HorizontalFieldManager.USE_ALL_WIDTH){
            public void paint(Graphics graphics)
            {
                super.paint(graphics);
                XYRect xy = getExtent();
                hieghtVFM = xy.Y2();
            }
        };
        for (int headerCount = 0; headerCount < col; ++headerCount)
        {
            sbData.delete(0, sbData.length());
            sbData.append(headerData[headerCount]);
            for(;:smileywink:{
                if(fnt.getAdvance(sbData.toString()) > columnWidth ) {
                    sbData.delete(sbData.length()-1, sbData.length());
                }
                else if(fnt.getAdvance(sbData.toString()) <= columnWidth-10){
                    sbData.append(' ');
                }else{
                    break;
                }
            }
           
            headings[headerCount] = new LabelField(sbData.toString(), LabelField.NON_FOCUSABLE)
            {
                public void paint(Graphics graphics)
                {
                    graphics.setBackgroundColor(Color.LIGHTGREEN);
                    graphics.clear();
                    super.paint(graphics);
                    graphics.drawRect(0, 0, columnWidth, getHeight());
                }
               
            };
            columnHeadingHolder.add(headings[headerCount]);
        }
       
        rowHolder = new HorizontalFieldManager(HorizontalFieldManager.NO_VERTICAL_SCROLL |
            HorizontalFieldManager.NO_HORIZONTAL_SCROLL);
           
        cols = new VerticalFieldManager[col];
        for (int colCount = 0; colCount < col; ++colCount)
        {
            cols[colCount] = new VerticalFieldManager(VerticalFieldManager.NO_HORIZONTAL_SCROLL |
                VerticalFieldManager.NO_VERTICAL_SCROLL){
                public void paint(Graphics graphics)
                {
                    graphics.setBackgroundColor(Color.LIGHTSALMON);
                    graphics.clear();
                    super.paint(graphics);
                }               
                public boolean navigationMovement(int dx, int dy, int status, int time){
                    boolean retResult = super.navigationMovement(dx, dy, status, time);
                    if(dx > 0 && (status == 536870912 || status == -1610612736)){
                        Field field = getLeafFieldWithFocus();
                        Manager mng = field.getManager();
                        if(mng.getIndex() < noOfCols-1){
                            lblField[field.getIndex()][mng.getIndex() + 1].setFocus();
                        }
                        return true;
                    }else if(dx < 0 && (status == 536870912 || status == -1610612736)){
                        Field field = getLeafFieldWithFocus();
                        Manager mng = field.getManager();
                        if(mng.getIndex() > 0){
                            lblField[field.getIndex()][mng.getIndex() - 1].setFocus();
                        }
                        return true;
                    }else if(dy > 0 && (status == 536870912 || status == -1610612736 || status == 1073741825)){
                        return retResult; 
                    }else if(dy < 0 && status == -1610612736 || status == 536870912 || status == -1073741823){
                        return retResult; 
                    }else{
                        return retResult;               
                    }
                }
            };
           
            for (int rowCount = 0; rowCount < row; ++rowCount)
            {               
                sbData.delete(0, sbData.length());
                sbData.append(gridData[rowCount][colCount]);

                for(;:smileywink:{
                    if(fnt.getAdvance(sbData.toString()) > columnWidth){
                        sbData.delete(sbData.length()-1, sbData.length());
                    }else if(fnt.getAdvance(sbData.toString()) <= columnWidth-10){
                        sbData.append(' ');
                    }else{
                        break;
                    }
                }

                lblField[rowCount][colCount] = new LabelField(sbData.toString(), LabelField.FOCUSABLE){
                    boolean flag = false;
                    protected void onFocus(int direction) {
                        flag = true;
                        super.onFocus(direction);
                        invalidate();
                    }
                    protected void onUnfocus() {
                        flag = false;
                        super.onUnfocus();
                        invalidate();
                    }                   
                    public void paint(Graphics graphics)
                    {
                        if(flag){
                            graphics.setBackgroundColor(Color.LIGHTGREY);
                        }else{
                            graphics.setBackgroundColor(Color.LIGHTPINK);
                        }
                        graphics.clear();
                        super.paint(graphics);
                        graphics.drawRect(0, 0, columnWidth, getHeight());
                    }
                   
                    protected void layout(int width,int height){
                        super.layout(width, height);
                    }
                };
                cols[colCount].add(lblField[rowCount][colCount]);
            }
            rowHolder.add(cols[colCount]);
        }           
        dataScroller = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL
                | VerticalFieldManager.VERTICAL_SCROLLBAR){
            protected void sublayout(int width, int height){
                super.sublayout(width, height);
                setExtent(widthVFM, hieghtVFM);
            }
        };

        dataScroller.add(rowHolder);

    }

    public VerticalFieldManager getControl(){
        return dataScroller;
    }
    public HorizontalFieldManager getControlHeading(){
        return columnHeadingHolder;
    }

}

Please use plain text.
Administrator
MSohm
Posts: 14,379
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Problem while moving focus horizontally in GridControl

Is there a reason you are calling super.navigationMovement in your navigationMovement method?  I think this should only be needed if you are not processing the movement.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.