BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-12-2010, 07:42 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2010
Model: 7100t
PIN: N/A
Carrier: VODAFONE
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default GridView Help Urgent

Please Login to Remove!

package com.bb.sample;

import javax.microedition.lcdui.Font;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManag er;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;

public class GridFieldManagerScreen extends MainScreen {
BitmapField bmpF1;
public GridFieldManagerScreen() {

// int column[]={5,5,5,5,5,5,5};

Manager screen = getMainManager();

screen
.setBackground(BackgroundFactory
.createSolidBackground(Color.RED));

GridFieldController gfc = new GridFieldController(3, 0);

bmpF1=new BitmapField(Bitmap.getBitmapResource("icon.png"),F IELD_HCENTER);


VerticalFieldManager vfmFirst=new VerticalFieldManager(FIELD_HCENTER)
{
protected void paintBackground(Graphics arg0) {
arg0.setBackgroundColor(Color.YELLOW);
arg0.clear();
super.paintBackground(arg0);
}


};

//BitmapField bmpF1=new BitmapField(Bitmap.getBitmapResource("icon.png"));
LabelField lbl1=new LabelField("First",FIELD_HCENTER);
vfmFirst.add(bmpF1);
vfmFirst.add(lbl1);
vfmFirst.setBorder(BorderFactory.createSimpleBorde r(new XYEdges(10,10,10,10), Border.STYLE_DASHED));


VerticalFieldManager vfmSecond=new VerticalFieldManager(FIELD_HCENTER){

protected void paintBackground(Graphics arg0) {
arg0.setBackgroundColor(Color.YELLOW);
arg0.clear();
super.paintBackground(arg0);
}


};

BitmapField bmpF2=new BitmapField(Bitmap.getBitmapResource("icon.png"),F IELD_HCENTER);
LabelField lbl2=new LabelField("Second",FIELD_HCENTER);
vfmSecond.add(bmpF2);
vfmSecond.add(lbl2);
vfmSecond.setBorder(BorderFactory.createSimpleBord er(new XYEdges(10,10,10,10), Border.STYLE_DASHED));

VerticalFieldManager vfmThird=new VerticalFieldManager(FIELD_HCENTER)
{
protected void paintBackground(Graphics arg0) {
arg0.setBackgroundColor(Color.YELLOW);
arg0.clear();
super.paintBackground(arg0);
}


};

BitmapField bmpF3=new BitmapField(Bitmap.getBitmapResource("icon.png"),F IELD_HCENTER);
LabelField lbl3=new LabelField("Third",FIELD_HCENTER);
vfmThird.add(bmpF3);
vfmThird.add(lbl3);
vfmThird.setBorder(BorderFactory.createSimpleBorde r(new XYEdges(10,10,10,10), Border.STYLE_DASHED));


VerticalFieldManager vfmForth=new VerticalFieldManager(FIELD_HCENTER){

protected void paintBackground(Graphics arg0) {
arg0.setBackgroundColor(Color.YELLOW);
arg0.clear();
super.paintBackground(arg0);
}

};

BitmapField bmpF4=new BitmapField(Bitmap.getBitmapResource("icon.png"),F IELD_HCENTER);
LabelField lbl4=new LabelField("Forth",FIELD_HCENTER);
vfmForth.add(bmpF4);
vfmForth.add(lbl4);
vfmForth.setBorder(BorderFactory.createSimpleBorde r(new XYEdges(10,10,10,10), Border.STYLE_DASHED));

VerticalFieldManager vfmFifth=new VerticalFieldManager(FIELD_HCENTER)
{
protected void paintBackground(Graphics arg0) {
arg0.setBackgroundColor(Color.YELLOW);
arg0.clear();
super.paintBackground(arg0);
}

};

BitmapField bmpF5=new BitmapField(Bitmap.getBitmapResource("icon.png"),F IELD_HCENTER);
LabelField lbl5=new LabelField("Fifth",FIELD_HCENTER);
vfmFifth.add(bmpF5);
vfmFifth.add(lbl5);
vfmFifth.setBorder(BorderFactory.createSimpleBorde r(new XYEdges(10,10,10,10), Border.STYLE_DASHED));

VerticalFieldManager vfmSixth=new VerticalFieldManager(FIELD_HCENTER)
{
protected void paintBackground(Graphics arg0) {
arg0.setBackgroundColor(Color.YELLOW);
arg0.clear();
super.paintBackground(arg0);
}


};

BitmapField bmpF6=new BitmapField(Bitmap.getBitmapResource("icon.png"),F IELD_HCENTER);
LabelField lbl6=new LabelField("Sixth",FIELD_HCENTER);
vfmSixth.add(bmpF6);
vfmSixth.add(lbl6);
vfmSixth.setBorder(BorderFactory.createSimpleBorde r(new XYEdges(10,10,10,10), Border.STYLE_DASHED));


VerticalFieldManager vfmSeventh=new VerticalFieldManager(FIELD_HCENTER)
{
protected void paintBackground(Graphics arg0) {
arg0.setBackgroundColor(Color.YELLOW);
arg0.clear();
super.paintBackground(arg0);
}

};

BitmapField bmpF7=new BitmapField(Bitmap.getBitmapResource("icon.png"),F IELD_HCENTER);
LabelField lbl7=new LabelField("Seventh",FIELD_HCENTER);
vfmSeventh.add(bmpF7);
vfmSeventh.add(lbl7);
vfmSeventh.setBorder(BorderFactory.createSimpleBor der(new XYEdges(10,10,10,10), Border.STYLE_DASHED));

gfc.add(vfmFirst);
gfc.add(vfmSecond);
gfc.add(vfmThird);
gfc.add(vfmForth);
gfc.add(vfmFifth);
gfc.add(vfmSixth);
gfc.add(vfmSeventh);


add(gfc);




}

}



//--------------------//----------------------//--------------------//----------------------//--------------------//---------------------//







package com.bb.sample;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;

public class GridFieldController 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 GridFieldController(int columns, long style) {
super(style);
this.columns = columns;
}


public GridFieldController(int[] columnWidths, long style) {
super(style);
this.columnWidths = columnWidths;
this.columns = columnWidths.length;
}

public GridFieldController(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));
}
}
Offline  
Old 11-12-2010, 07:58 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default Re: GridView Help Urgent

Is there a question in this threads future? Also formatting the code as requested on this sticky thread would help a great deal: How to paste 100% FORMATTED Source Code In Your Forum Posts
__________________
My other Blackberry is a PlayBook.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads for: GridView Help Urgent
Thread Thread Starter Forum Replies Last Post
Urgent :: Download Link 9000 v5.0.0.1385 ??? Maksa General 9000 Series Discussion - Bold 2 09-09-2010 01:26 AM
Need Help Urgent sonamkbr RIM Software 8 04-07-2010 12:41 PM
GSM & CDMA Prob..Its urgent pls help Durgm Developer Forum 2 10-12-2009 07:23 AM
URGENT...very very URGENT...can't get bbm 4.6 (my original one) genius_1991 General 9000 Series Discussion - Bold 5 07-26-2009 04:45 AM
I want the text with blinking effect (urgent Please) harikak Developer Forum 5 06-06-2008 07:28 AM





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.