09-24-2010 12:51 AM
how to create a table in blackberry i am usign blackberry jde 4.7.which class to use inorder to create a table with two columns and five rows.can any one give sample code for this.I searched in google but i did not find a suitable one.
Solved! Go to Solution.
09-24-2010 01:21 AM
u can use GridFieldManager inorder to create rows and coloums...Here is a sample code for dat:
http://docs.blackberry.com/en/developers/deliverab
09-24-2010 01:33 AM
09-24-2010 05:24 AM
i have implemented the code but i am getting the cannot find the class GridFieldManager GridFieldManager grid = new GridFieldManager(2,3,0);
09-24-2010 05:38 AM
Till jde 4.7 no Class available for this. So u can create Custom Grid Manager
09-28-2010 05:57 AM
i have implemented the part of code and wrote the main screen class also then i was able to see a blank screen and not the table here is my code.
--------------------------------------------------
/*
* GridFieldManagerDemo.java
*
* © <your company here>, 2003-2008
* Confidential and proprietary.
*/
package GridFieldManager;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.Manager.*;
import net.rim.device.api.ui.container.MainScreen.*;
/**
*
*/
class GridFieldManagerDemo extends UiApplication
{
public static void main(String args[])
{
GridFieldManagerDemo gfmd = new GridFieldManagerDemo();
gfmd.enterEventDispatcher();
}
public GridFieldManagerDemo()
{
pushScreen(new GridFieldScreen());
}
}
--------------------------------------------------
/*
* GridFieldScreen.java
*
* © <your company here>, 2003-2008
* Confidential and proprietary.
*/
package GridFieldManager;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.Manager.*;
import net.rim.device.api.ui.container.MainScreen.*;
/**
*
*/
class GridFieldScreen extends MainScreen
{
private int[] columnWidths;
private int columns;
private int allRowHeight = -1;
public GridFieldScreen()
{
super();
setTitle("GridFieldManagerDemo");
GridFieldManager gfm = new GridFieldManager(10,GridFieldManager.USE_ALL_WIDTH
//GridFieldManager gfm = new GridFieldManager(2,50,GridFieldManager.USE_ALL_WID
// GridFieldManager gfm = new GridFieldManager(2,GridFieldManager.USE_ALL_WIDTH)
//gfm.navigationMovement(3,2,1,100);
add(gfm);
}
}
--------------------------------------------------
/*
* GridFieldManager.java
*
* © <your company here>, 2003-2008
* Confidential and proprietary.
*/
package GridFieldManager;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
public class GridFieldManager extends Manager {
private int[] columnWidths;
private int columns;
private int allRowHeight = -1;
/**
* Constructs a new GridFieldManager with the specified number of columns.
* Rows will be added as needed to display fields.
* Fields will be added to the grid in the order they are added to this manager,
* filling up each row left-to-right:
*
* For example a 2 column manager:
*
* [Field1][Field2]
* [Field3][Field4]
* [Field5]
*
* Column widths are all equal, and the manager will attempt to use all available width.
* The height of each row will be equal to the height of the tallest Field in that row.
* Field positional styles are respected, so fields that are smaller than the row/column
* they are in can be positioned left, right, top bottom, or centered. They default to top left.
*
* @param columns Number of columns in the grid
* @param style
*/
public GridFieldManager(int columns, long style) {
super(style);
this.columns = columns;
}
public GridFieldManager(int[] columnWidths, long style) {
super(style);
this.columnWidths = columnWidths;
this.columns = columnWidths.length;
}
public GridFieldManager(int[] columnWidths, int rowHeight, long style) {
this(columnWidths, style);
this.allRowHeight = rowHeight;
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
int focusIndex = getFieldWithFocusIndex();
while(dy > 0) {
focusIndex += columns;
if (focusIndex >= getFieldCount()) {
return false; // Focus moves out of this manager
}
else {
Field f = getField(focusIndex);
if (f.isFocusable()) { // Only move the focus onto focusable fields
f.setFocus();
dy--;
}
}
}
while(dy < 0) {
focusIndex -= columns;
if (focusIndex < 0) {
return false;
}
else {
Field f = getField(focusIndex);
if (f.isFocusable()) {
f.setFocus();
dy++;
}
}
}
while(dx > 0) {
focusIndex ++;
if (focusIndex >= getFieldCount()) {
return false;
}
else {
Field f = getField(focusIndex);
if (f.isFocusable()) {
f.setFocus();
dx--;
}
}
}
while(dx < 0) {
focusIndex --;
if (focusIndex < 0) {
return false;
}
else {
Field f = getField(focusIndex);
if (f.isFocusable()) {
f.setFocus();
dx++;
}
}
}
return true;
}
protected void sublayout(int width, int height) {
int y = 0;
if (columnWidths == null) {
columnWidths = new int[columns];
for(int i = 0; i < columns; i++) {
columnWidths[i] = width/columns;
}
}
Field[] fields = new Field[columnWidths.length];
int currentColumn = 0;
int rowHeight = 0;
for(int i = 0; i < getFieldCount(); i++) {
fields[currentColumn] = getField(i);
layoutChild(fields[currentColumn], columnWidths[currentColumn], height-y);
if (fields[currentColumn].getHeight() > rowHeight) {
rowHeight = fields[currentColumn].getHeight();
}
currentColumn++;
if (currentColumn == columnWidths.length || i == getFieldCount()-1) {
int x = 0;
if (this.allRowHeight >= 0) {
rowHeight = this.allRowHeight;
}
for(int c = 0; c < currentColumn; c++) {
long fieldStyle = fields[c].getStyle();
int fieldXOffset = 0;
long fieldHalign = fieldStyle & Field.FIELD_HALIGN_MASK;
if (fieldHalign == Field.FIELD_RIGHT) {
fieldXOffset = columnWidths[c] - fields[c].getWidth();
}
else if (fieldHalign == Field.FIELD_HCENTER) {
fieldXOffset = (columnWidths[c]-fields[c].getWidth())/2;
}
int fieldYOffset = 0;
long fieldValign = fieldStyle & Field.FIELD_VALIGN_MASK;
if (fieldValign == Field.FIELD_BOTTOM) {
fieldYOffset = rowHeight - fields[c].getHeight();
}
else if (fieldValign == Field.FIELD_VCENTER) {
fieldYOffset = (rowHeight-fields[c].getHeight())/2;
}
setPositionChild(fields[c], x+fieldXOffset, y + fieldYOffset);
x += columnWidths[c];
}
currentColumn = 0;
y += rowHeight;
}
if (y >= height) {
break;
}
}
int totalWidth = 0;
for(int i = 0; i < columnWidths.length; i++) {
totalWidth += columnWidths[i];
}
setExtent(totalWidth, Math.min(y, height));
}
}
--------------------------------------------------
09-28-2010 06:36 AM
Hi,
Your code is Perfect and work fine. The problem with you is that you do not add any thing in manager for display. So take some field to add in gfm.
or replace your GridFieldScreen.java constructor with below code
public GridFieldScreen()
{
super();
setTitle("GridFieldManagerDemo");
GridFieldManager gfm = new GridFieldManager(2,GridFieldManager.USE_ALL_WIDTH) ;
LabelField l1=new LabelField("1");
LabelField l2=new LabelField("2");
LabelField l3=new LabelField("3");
LabelField l4=new LabelField("4");
LabelField l5=new LabelField("5");
gfm.add(l1);
gfm.add(l2);
gfm.add(l3);
gfm.add(l4);
gfm.add(l5);
add(gfm);
}Thanks
Vivek
09-28-2010 08:17 AM
Thanks aman i will try that
09-29-2010 02:23 AM
11-22-2010 07:36 AM
hi ,
Saw ur post for creating table...took ur sample ocde which you have posted and tried it...Am getting it......i need to display the table using borders which will be seperating and showing the rows and columns....Can u please help me...Any link as a refernce for doing that will be gratefully appreciated...
With regards
Sunil