In BlackBerry UI Right Align Issue - blackberry

In BlackBerry UI I am trying to align some LabelFields Right aligned and left aligned:
For this I have created one VertiFieldManager at top level then Adding a HorizontalFieldmanager to it and all lalbelFields are added to horizontalFieldManager,
Horizontal field Manager is forcing content to Left aligned.
How can I align the fields in Right side?
I tried spacing but it does not looks good in BB devices having different Pixcels resolution.
Please advise.

i'm still new on BB, but have you tried to change Long style for the HorizontalField ?

try this code -
JustifiedHorizontalFieldManager j=new JustifiedHorizontalFieldManager(new NullField(),your_field, true);
add(j);
//JustifiedHorizontalFieldManager class is given below.
public class JustifiedHorizontalFieldManager extends Manager
{
private static final int SYSTEM_STYLE_SHIFT = 32;
public Field _leftField;
public Field _rightField;
private boolean _giveLeftFieldPriority;
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
{
this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
super( style );
_leftField = leftField;
_rightField = rightField;
add( _leftField );
add( _rightField );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
super( style );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public void addLeftField( Field field )
{
if( _leftField != null ) {
throw new IllegalStateException();
}
_leftField = field;
add( _leftField );
}
public void addRightField( Field field )
{
if( _rightField != null ) {
throw new IllegalStateException();
}
_rightField = field;
add( _rightField );
}
public int getPreferredWidth()
{
return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}
public int getPreferredHeight()
{
return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}
protected void sublayout( int width, int height )
{
Field firstField;
Field secondField;
if( _giveLeftFieldPriority ) {
firstField = _leftField;
secondField = _rightField;
} else {
firstField = _rightField;
secondField = _leftField;
}
int maxHeight = 0;
int availableWidth = width;
availableWidth -= _leftField.getMarginLeft();
availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
availableWidth -= _rightField.getMarginRight();
layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
availableWidth -= firstField.getWidth();
layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
availableWidth -= secondField.getWidth();
if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
height = maxHeight;
}
if( !isStyle( Field.USE_ALL_WIDTH ) ) {
width -= availableWidth;
}
setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );
setExtent( width, height );
}
private int getFieldY( Field field, int height )
{
switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
return height - field.getHeight() - field.getMarginBottom();
case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
default:
return field.getMarginTop();
}
}
public Field getLeftField()
{
return _leftField;
}
public Field getRightField()
{
return _rightField;
}
public void replace( Field oldField, Field newField )
{
if( oldField == newField ) {
// Nothing to do
return;
}
if( oldField == _leftField ) {
_leftField = newField;
} else if( oldField == _rightField ) {
_rightField = newField;
}
add( newField );
delete( oldField );
}
}

There are no nice solution unfortunately. The smaller than previous I think this:
HorizontalFieldManager hfm = new HorizontalFieldManager();
LabelField leftField = new LabelField("One");
hfm.add(leftField);
LabelField rightField = new LabelField("Two", LabelField.USE_ALL_WIDTH | DrawStyle.RIGHT);
hfm.add(rightField);
Basically we use all available width area for second field and ask it to draw text as right aligned.
This solution is Ok because LabeLField is not focusable. As soon as you have to deal with focusable fields use solution from #Signare.

Related

Chat Window Design - Blackberry

I try to implement a Chat window( Chat functionality work fine & smooth). I am facing problem in designing Middle & Bottom part. In middle part chat messages & bottom i want to add editable field. If i fixed editable field align bottom chat messages not show, & if i add editable field after bottom, then chat messages shown on screen.
I have used NegativeMarginVerticalFieldManager.
I want field attached bottom of screen & messages show middle with scrollbar. Here i also attach code that i used in chat with dummy messages(without Json data). Thanks
package mypackage;
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.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.*;
public class ChatList extends MainScreen
{
Manager _foreground = new NegativeMarginVerticalFieldManager( USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL );
BasicEditField msg;
public ChatList() {
super( NO_VERTICAL_SCROLL );
setTitle( "Chat" );
// Set the linear background.
this.getMainManager().setBackground(
BackgroundFactory.createLinearGradientBackground(0x91e7ff,0x0099CCFF,0x00336699,0x91e7ff)
);
// Add Field Bottom
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_BOTTOM);
msg = new BasicEditField();
msg.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x999999, Border.STYLE_FILLED));
msg.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
msg.setPadding(5,0,5,0);
msg.setMargin(0,10,0,10);
vfm.add(msg);
hfm.add(vfm);
add(hfm);
}
public boolean keyDown(int keycode, int time) {
if (Keypad.KEY_ENTER == Keypad.key(keycode)) {
String message = msg.getText();
if(!message.equals(""))
{
Border rightBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 23, 27, 16 ), Bitmap.getBitmapResource( "border_bubble_right.png" ) );
Border leftBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 16, 27, 23 ), Bitmap.getBitmapResource( "border_bubble_left.png" ) );
addHeading( "Hello Adil!", leftBorder, Field.FIELD_LEFT );
addHeading( "Yeah, I see it", rightBorder, Field.FIELD_RIGHT );
addHeading( "have any update , related to this??", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Middle part Messages", leftBorder, Field.FIELD_LEFT );
addHeading( "Vertically Scroll add in messages", leftBorder, Field.FIELD_LEFT );
addHeading( "have any update!", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Bottom Alignment Basic Editable Field?", leftBorder, Field.FIELD_LEFT );
addHeading( "Probably", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
msg.setText("");
// ADD ALL FIELDS
add( _foreground );
}// if condition
else{ Dialog.alert("Please insert message");}
return true;
}
//let the system to pass the event to another listener.
return false;
}
private void addHeading( String label, Border border, long style )
{
LabelField header = new LabelField( label, Field.FOCUSABLE | style );
header.setBorder( border );
header.setMargin( 5, 5, -15, 5 );
_foreground.add( header );
}
}
try this - (i modified your code little bit.)
public class ChatList extends MainScreen
{
Manager _foreground = new NegativeMarginVerticalFieldManager( USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL );
BasicEditField msg;
public ChatList() {
super( NO_VERTICAL_SCROLL );
setTitle( "Chat" );
// Set the linear background.
this.getMainManager().setBackground(
BackgroundFactory.createLinearGradientBackground(0x91e7ff,0x0099CCFF,0x00336699,0x91e7ff)
);
// Add Field Bottom
HorizontalFieldManager hfm = new HorizontalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth()/2+60,20); setExtent(Display.getWidth()/2+60,20);
}
};
msg = new BasicEditField(){
};
msg.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x999999, Border.STYLE_FILLED));
msg.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
// msg.setPadding(5,0,5,0);
msg.setPadding(5,0,5,0);
msg.setMargin(0,10,0,10);
hfm.add(msg);
final ButtonField b=new ButtonField("send");
JustifiedHorizontalFieldManager jfm=new JustifiedHorizontalFieldManager(hfm, b,true);
setStatus(jfm);
FieldChangeListener listener=new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if(field==b){
Border rightBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 23, 27, 16 ), Bitmap.getBitmapResource( "bubble_right.png" ) );
Border leftBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 16, 27, 23 ), Bitmap.getBitmapResource( "bubble_left.png" ) );
addHeading( "Hello Adil!", leftBorder, Field.FIELD_LEFT );
addHeading( "Yeah, I see it", rightBorder, Field.FIELD_RIGHT );
addHeading( "have any update , related to this??", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Middle part Messages", leftBorder, Field.FIELD_LEFT );
addHeading( "Vertically Scroll add in messages", leftBorder, Field.FIELD_LEFT );
addHeading( "have any update!", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Bottom Alignment Basic Editable Field?", leftBorder, Field.FIELD_LEFT );
addHeading( "Probably", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
msg.setText("");
// ADD ALL FIELDS
add( _foreground );
}
}
};
b.setChangeListener(listener);
}
private void addHeading( String label, Border border, long style )
{
LabelField header = new LabelField( label, Field.FOCUSABLE | style );
header.setBorder( border );
header.setMargin( 5, 5, -15, 5 );
_foreground.add( header );
}
}
JustifiedHorizontalFieldManager.java is given below -
public class JustifiedHorizontalFieldManager extends Manager
{
private static final int SYSTEM_STYLE_SHIFT = 32;
public Field _leftField;
public Field _rightField;
private boolean _giveLeftFieldPriority;
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
{
this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
super( style );
_leftField = leftField;
_rightField = rightField;
add( _leftField );
add( _rightField );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
super( style );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public void addLeftField( Field field )
{
if( _leftField != null ) {
throw new IllegalStateException();
}
_leftField = field;
add( _leftField );
}
public void addRightField( Field field )
{
if( _rightField != null ) {
throw new IllegalStateException();
}
_rightField = field;
add( _rightField );
}
public int getPreferredWidth()
{
return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}
public int getPreferredHeight()
{
return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}
protected void sublayout( int width, int height )
{
Field firstField;
Field secondField;
if( _giveLeftFieldPriority ) {
firstField = _leftField;
secondField = _rightField;
} else {
firstField = _rightField;
secondField = _leftField;
}
int maxHeight = 0;
int availableWidth = width;
availableWidth -= _leftField.getMarginLeft();
availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
availableWidth -= _rightField.getMarginRight();
layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
availableWidth -= firstField.getWidth();
layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
availableWidth -= secondField.getWidth();
if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
height = maxHeight;
}
if( !isStyle( Field.USE_ALL_WIDTH ) ) {
width -= availableWidth;
}
setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );
setExtent( width, height );
}
private int getFieldY( Field field, int height )
{
switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
return height - field.getHeight() - field.getMarginBottom();
case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
default:
return field.getMarginTop();
}
}
public Field getLeftField()
{
return _leftField;
}
public Field getRightField()
{
return _rightField;
}
public void replace( Field oldField, Field newField )
{
if( oldField == newField ) {
// Nothing to do
return;
}
if( oldField == _leftField ) {
_leftField = newField;
} else if( oldField == _rightField ) {
_rightField = newField;
}
add( newField );
delete( oldField );
}
}

How can i select a drop down which i added over a list field?

Hi Friend's in my BlackBerry Application i use a list Field, and over this list Field i add a drop down. Now my problem is how do i select the drop down which i added over the list Field.Now i only select list field and not the drop down but my requirement is first i should select the drop down and then list field. I have included my code here please check it.
public class TaskListField extends ListField implements ListFieldCallback, KeypadListener {
private Vector rows;
private Bitmap p1;
private Bitmap p2;
public LoginPage objLoginPage;
public String[] data={"Call","Visit"};
public String strIndex = null;
public int tempIndex = 0;
public int intvalue;
public int id;
public int value;
public boolean hasFocus = false;
public static String[] arrOutletName = { "Dosa Store", "Benfish Bhawan",
"Nalban Park", "Korunamoyee", "206 Bus Stop", "aaaaaaaa",
"bbbbbbbb", "ccccccccc", "dddddddd", "eeeeeee" };
public ObjectChoiceField ocf;
public TaskListField() {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
setCallback(this);
p1 = Bitmap.getBitmapResource("name.png");
p2 = Bitmap.getBitmapResource("name.png");
rows = new Vector();
for (int x = 0; x < XmlHander.vectSrno.size(); x++) {
TableRowManager row = new TableRowManager();
strIndex = String.valueOf(x);
String strVectno = XmlHander.vectSrno.elementAt(x).toString();
String strSLADate = XmlHander.vectSldate.elementAt(x).toString();
if (x % 2 == 0) {
row.add(new BitmapField(null));
}
else {
row.add(new BitmapField(null));
}
LabelField task = new LabelField(" ");
if (x % 15 == 0) {
task.setFont(Font.getDefault().derive(Font.BOLD | Font.UNDERLINED));
} else {
task.setFont(Font.getDefault().derive(Font.BOLD));
}
row.add(task);
row.add(new LabelField(strVectno, DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
// graphics.setColor(Color.PINK);
super.paint(graphics);
}
});
row.add(ocf=new ObjectChoiceField("",data){
protected void paint(Graphics graphics){
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
ocf.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context) {
if(context != PROGRAMMATIC)
Dialog.alert(data[ocf.getSelectedIndex()]);
}
});
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
TaskListField list = (TaskListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
protected boolean navigationClick(int status, int time) {
final int index;
index = this.getFieldWithFocusIndex() - 1;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new Details(id));
}
});
return false;
}
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
id = this.getSelectedIndex();
invalidate();
return super.moveFocus(amount, status, time);
}
public void onFocus(int direction) {
hasFocus = true;
super.onFocus(direction);
System.out.println("direction==" + direction);
invalidate();
}
public void onUnfocus() {
updateLayout();
super.onUnfocus();
invalidate();
}
private int getFieldWithFocusIndex() {
return 0;
}
}

how to show couple of data in blackberry on single screen

Hi Friend's how can i show couple of data in blackberry on a single screen.
for example:
current Date------------value.
Name------------------- value.
roll--------------------value.
email-id----------------value.
phone-no----------------value.
pass--------------------value.
class-------------------value.
sex---------------------value.
college-----------------value.
city--------------------value.
state-------------------value.
pin code----------------value.
country-----------------value.
public LabelField lbSr, lbDate, lbAllo, lbMob, lbDetail, lbRemark, lbSlaDate, lbEmail, lbStatus, lbspace;
public LabelField lb1Sr, lb1Date, lb1Allo, lb1Mob, lb1Detail, lb1Remark, lb1SlaDate, lb1Email, lb1Status;
public JustifiedHorizontalFieldManager jhfm1,jhfm2,jhfm3,jhfm4,jhfm5,jhfm6,jhfm7,jhfm8,jhfm9;
VerticalFieldManager vfm=new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL);
lb1Sr = new LabelField("SRNo :");
lb1Sr.setColor(Color.BLACK);
lbSr = new LabelField(strSerno);
lbSr.setColor(Color.BLACK);
lb1Date = new LabelField("SRDate :");
lb1Date.setColor(Color.BLACK);
lbDate = new LabelField(strDate);
lbDate.setColor(Color.BLACK);
lb1Allo = new LabelField("AllocDate :");
lb1Allo.setColor(Color.BLACK);
lbAllo = new LabelField(strAllo);
lbAllo.setColor(Color.BLACK);
lb1Mob = new LabelField("MobNo :");
lb1Mob.setColor(Color.BLACK);
lbMob = new LabelField(strMob);
lbMob.setColor(Color.BLACK);
lb1Detail = new LabelField("SRDetails :");
lb1Detail.setColor(Color.BLACK);
lbDetail = new LabelField(strDetail);
lbDetail.setColor(Color.BLACK);
lb1Remark = new LabelField("Remarks :");
lb1Remark.setColor(Color.BLACK);
lbRemark = new LabelField(strRemark);
lbRemark.setColor(Color.BLACK);
lb1SlaDate = new LabelField("SLADate :");
lb1SlaDate.setColor(Color.BLACK);
lbSlaDate = new LabelField(strSldate);
lbSlaDate.setColor(Color.BLACK);
lb1Email = new LabelField("Email :");
lb1Email.setColor(Color.BLACK);
lbEmail = new LabelField(strEmail);
lbEmail.setColor(Color.BLACK);
lb1Status = new LabelField("Status :");
lb1Status.setColor(Color.BLACK);
lbStatus = new LabelField(strStatus);
lbStatus.setColor(Color.BLACK);
jhfm1=new JustifiedHorizontalFieldManager(lb1Sr, lbSr, true);
vfm.add(jhfm1);
jhfm2=new JustifiedHorizontalFieldManager(lb1Date, lbDate, true);
vfm.add(jhfm2);
jhfm3=new JustifiedHorizontalFieldManager(lb1Allo, lbAllo, true);
vfm.add(jhfm3);
jhfm4=new JustifiedHorizontalFieldManager(lb1Mob, lbMob, true);
vfm.add(jhfm4);
hfm5=new JustifiedHorizontalFieldManager(lb1Detail, lbDetail, true);
vfm.add(jhfm5);
jhfm6=new JustifiedHorizontalFieldManager(lb1Remark, lbRemark, true);
vfm.add(jhfm6);
jhfm7=new JustifiedHorizontalFieldManager(lb1SlaDate, lbSlaDate, true);
vfm.add(jhfm7);
jhfm8=new JustifiedHorizontalFieldManager(lb1Email, lbEmail, true);
vfm.add(jhfm8);
jhfm9=new JustifiedHorizontalFieldManager(lb1Status, lbStatus, true);
vfm.add(jhfm9);
add(vfm);
I want to show all data with both side scroll option.
try this code -
VerticalFieldManager vfm=new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL);
LabelField date=new LabelField("Date :");
LabelField date_value=new LabelField(value);
JustifiedHorizontalFieldManager jfm_date=new JustifiedHorizontalFieldManager(date,date_value, true);
vfm.add(jfm_date);
LabelField name=new LabelField("Name:");
LabelField name_value=new LabelField(value);
JustifiedHorizontalFieldManager jfm_name=new JustifiedHorizontalFieldManager(name,name_value, true);
vfm.add(jfm_name);
add(vfm);
And so on....add all the fields like this.
JustifiedHorizontalFieldManager class is given below-
public class JustifiedHorizontalFieldManager extends Manager
{
private static final int SYSTEM_STYLE_SHIFT = 32;
public Field _leftField;
public Field _rightField;
private boolean _giveLeftFieldPriority;
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
{
this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
super( style );
_leftField = leftField;
_rightField = rightField;
add( _leftField );
add( _rightField );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
super( style );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public void addLeftField( Field field )
{
if( _leftField != null ) {
throw new IllegalStateException();
}
_leftField = field;
add( _leftField );
}
public void addRightField( Field field )
{
if( _rightField != null ) {
throw new IllegalStateException();
}
_rightField = field;
add( _rightField );
}
public int getPreferredWidth()
{
return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}
public int getPreferredHeight()
{
return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}
protected void sublayout( int width, int height )
{
Field firstField;
Field secondField;
if( _giveLeftFieldPriority ) {
firstField = _leftField;
secondField = _rightField;
} else {
firstField = _rightField;
secondField = _leftField;
}
int maxHeight = 0;
int availableWidth = width;
availableWidth -= _leftField.getMarginLeft();
availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
availableWidth -= _rightField.getMarginRight();
layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
availableWidth -= firstField.getWidth();
layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
availableWidth -= secondField.getWidth();
if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
height = maxHeight;
}
if( !isStyle( Field.USE_ALL_WIDTH ) ) {
width -= availableWidth;
}
setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );
setExtent( width, height );
}
private int getFieldY( Field field, int height )
{
switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
return height - field.getHeight() - field.getMarginBottom();
case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
default:
return field.getMarginTop();
}
}
public Field getLeftField()
{
return _leftField;
}
public Field getRightField()
{
return _rightField;
}
public void replace( Field oldField, Field newField )
{
if( oldField == newField ) {
// Nothing to do
return;
}
if( oldField == _leftField ) {
_leftField = newField;
} else if( oldField == _rightField ) {
_rightField = newField;
}
add( newField );
delete( oldField );
}
}

BlackBerry - How to add clickEvent (setChangeListener) to ListField in BlackBerry?

I'm using ListField in Blackberry and unable to apply the row.setChangeListener.
Can anybody please help me?
Here is my code,
Friendship objFriendship = new Friendship();
friends = objFriendship.FetchFriends(AATTGlobals.CURRENT_USER.getUserID());
rows = new Vector();
for (int x = 0; x < friends.length; x++) {
String UserName = friends[x].getUserName();
ProfilePicture = MISC.FetchUserProfilePicture(friends[x].getProfilePicturePath());
String Location = friends[x].getLocation();
TableRowManager row = new TableRowManager();
row.add(new BitmapField(ProfilePicture));
LabelField task = new LabelField(UserName,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
};
task.setFont(Font.getDefault().derive(Font.BOLD));
row.add(task);
row.add(new LabelField(Location,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
}
);
row.setChangeListener( new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.alert("Row Clicked #");
}
});
No any error message but setChangeListener doesn't fire, here is TableRowManager
Private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x0099CCFF);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 44, 44);
setPositionChild(field, 10, getRowHeight() / 4);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 70, getRowHeight() / 5);
field = getField(2);
layoutChild(field, field.getPreferredWidth(), fontHeight + 1);
setPositionChild(field, 70, (getRowHeight() / 2) + 5);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
in tableRowManager add this
//for non touch
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
//for touch
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
try this let me know is it working or not.
I noticed, fieldChangeLister/FieldChanged isnt getting called with ListField UI [as it works for button and labels.]So I think FieldChanged is not supported with Listfield
In navigationClick/TouchEvent (), write the action you are writing in FieldChange method.

how to create a list field as same style as BlackBerry facebook?

how to create a list field as same style as Black Berry facebook ?
the RIM list field contains only text, i want to create list field that can contains other fields such as image, text area and href link .
I managed to create it ,and it works fine but the the fields inside the list item never gain focus , any idea how do it ?
public class RichListField extends ListField implements ListFieldCallback {
private Vector rows;
public RichListField(String emtpyString, RichListItem[] items) {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString(emtpyString, DrawStyle.HCENTER);
setCallback(this);
rows = new Vector();
for (int i = 0; i < items.length; i++) {
TableRowManager row = new TableRowManager();
row.add(new BitmapField(items[i].getBitmap()));
LabelField itemLabel = new LabelField(items[i].getLabel(),
DrawStyle.ELLIPSIS);
// mark selected
// itemLabel.setFont(Font.getDefault().derive(
// Font.BOLD | Font.UNDERLINED));
itemLabel.setFont(Font.getDefault().derive(Font.BOLD));
row.add(itemLabel);
// SET THE LIST Item description
row.add(new LabelField(items[i].getDescription(),
DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
row.add(items[i].getLink());
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
RichListField list = (RichListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows
.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
// start with the Bitmap Field of the priority icon
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
// set the label field
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the description label field
field = getField(2);
layoutChild(field, preferredWidth, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
// set the Href field
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
//To set the required dimensions for the field
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Display.getWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
public class RichListItem {
private String label;
private Bitmap bitmap;
private String description;
private HrefField link;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public HrefField getLink() {
return link;
}
public void setLink(HrefField link) {
this.link = link;
}
public RichListItem(String label, Bitmap bitmap, String description,
HrefField link) {
super();
this.label = label;
this.bitmap = bitmap;
this.description = description;
this.link = link;
}
}
You just need to add 2 lines of code at drawListRow when implement interface ListFieldCallback.
if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) rowColor = Color.RED;
else rowColor = Color.GRAY
If all you want to do is change the color when a row has focus, you could override ListField.drawFocus():
protected void drawFocus(Graphics graphics, boolean on) {
if (on) {
graphics.setColor(focusColor);
graphics.setBackgroundColor(focusBackgroundColor);
super.drawFocus(graphics, on);
/**
You may have to play with the call to super.drawFocus() depending on
what it actually does. For example:
super.drawFocus(graphics, false);
may work better. Or you may have to draw the field yourself.
*/
}
}

Resources