05-28-2012 04:42 AM
Hi everyone,
i am having a hard time trying to handle rotation for GridFieldManager.
I set the column properties as GridFieldManager.FIXED_SIZE. I add the data to the grid. Then i add the grid to an absolute layout manager. And when rotation occurs, i change the column properties in sublayout of absolute layout manager. Nothing changes.
Could you please suggest a better approach for this issue ?
Regards,
Solved! Go to Solution.
05-28-2012 05:58 AM - edited 05-29-2012 05:02 AM
"I change the column properties in sublayout of absolute layout manager"
Are you sure this completes? I suspect that you will then cause the GridFieldManager to attempt to relayout itself, but it is in the middle of that processing anyway, so this will probably throw some sort of Exception.
Wrap your code in an an invokeLater, and initiate it in the sublayout of the GridFieldManager, but because it is in an invokeLater, the initial layout will have completed before this code gets control.
Of course the second option is that you can't actually change the proportions once defined - never used this Manager myself so am not sure. Anyway, another option is to create a new GridFieldManager and in the invokeLater code, swap it in, in place of the old one.
05-29-2012 04:39 AM
Hi, thank you for your answer.
I moved the code inside an invoke later block but unfortunately nothing changed. And i wasn' t able to replace the grid with a new one either. (Because of legacy code, i might work on that later.)
I have a new question regarding my grid field problem. Below is a sample code i found from the net. A simple grid field example. Could you please explain me why the grid field expands everytime i made a rotation(tilt) on the simulator ? Because i really dont get it...
Regards,
package mypackage;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class ScreenWidthGridExample extends MainScreen {
private static final int NUM_ROWS = 1;
/**
* Number of columns in the grid.
*/
private static final int NUM_COLUMNS = 4;
/**
* The grid's column padding.
*/
private static final int COLUMN_PADDING = 5;
/**
* Toggle switch to show the border around the grid.
*/
private static final boolean SHOW_BORDER = true;
/**
* Allocated a new instance of the ScreenWidthGridExample.
*/
ScreenWidthGridExample () {
// Set up the GridFieldManager
GridFieldManager gfm = new GridFieldManager(NUM_ROWS, NUM_COLUMNS, GridFieldManager.FIXED_SIZE);
gfm.setColumnPadding(COLUMN_PADDING);
if (SHOW_BORDER) {
gfm.setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0), // top, right, bottom, left
Border.STYLE_DASHED));
}
add(gfm);
// Size the columns of the GridFieldManager. Make sure to calculate
// for the padding applied to the columns.
int columnWidth = (Display.getWidth() / NUM_COLUMNS) - gfm.getColumnPadding();
for (int i = 0; i < NUM_COLUMNS; i++) {
gfm.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
}
// Populate the columns.
gfm.add(new ButtonField("1", Field.FIELD_HCENTER));
gfm.add(new ButtonField("2", Field.FIELD_HCENTER));
gfm.add(new ButtonField("3", Field.FIELD_HCENTER));
gfm.add(new ButtonField("4", Field.FIELD_HCENTER));
}
/* protected void sublayout(int width, int height) {
super.sublayout(width, height);
for (int i = 0; i < this.getFieldCount(); i++) {
Field field = this.getField(i);
if (field instanceof GridFieldManager) {
int columnWidth = (Display.getWidth() / NUM_COLUMNS) - ((GridFieldManager) field).getColumnPadding();
for (int j = 0; j < NUM_COLUMNS; j++) {
((GridFieldManager) field).setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
}
((GridFieldManager) field).invalidate();
}
}
}*/
}
05-29-2012 05:06 AM
I don't see the GridFieldManager code in there, I presume it is that code that is changing things.
There was a GridFieldManager floating round that originally seemed to come from code supplied by Anthony Rizk in his book "Beginning BlackBerry Development". I looked at that code, but for doing this sort of layout, I prefer TableLayoutManager, which is a bit of RIM supplied code. You will find it here:
05-29-2012 05:57 AM
peter_strange wrote:I don't see the GridFieldManager code in there, I presume it is that code that is changing things.
it is imported. I am new to blackberry development but isn't that manager part of blackberry api ? It says on the javadoc it is in since BlackBerry API 5.0.0.
Thanks for the link, i will have a look at it and see if i can use it to replace grid field manager.
05-29-2012 07:03 AM
Sorry my mistake. You are right it is imported.
Since I have never used GridFieldManager I think I should leave this to someone who has.
05-30-2012 07:41 AM
Hi Peter,
I did replace the GridFieldManager with the table layout manager on the link you provided and it works just fine. I am able to rotate the table now.
Thank you very much.
Regards,