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
Developer
pav52
Posts: 46
Registered: ‎12-01-2009
My Device: Not Specified

Editable TextField Alignment

[ Edited ]

Hey guys,

 

I've got a TextField with a label inside a VerticalFieldManager with looks like this:

 

+--------------------------------+

| Label: EditableText         |

+--------------------------------+

 

What I'd like to achieve is having EditableText be aligned to the right, as follows:

 

+--------------------------------+

| Label:         EditableText |

+--------------------------------+

 

What's the simplest way to achieve this?

 

Update:

- I've separated Label and EditableText into two separate fields, which I assume will make this easier. They are now inside a HorizontalFieldManager.

 

Can the HorizontalFieldManager be told to use all width and share the space evenly among the fields in it? 50/50.

 

In addition, I need a way to force Label to be left-aligned (easy -- this is the default alignment) and force EditableText to be right-aligned.

 

 

Cheers,

Pav

 

Developer
pav52
Posts: 46
Registered: ‎12-01-2009
My Device: Not Specified

Re: Editable TextField Alignment

Anyone?

 

Note that ChoiceField is right-aligned by default... isn't there a way to make TextField be right-aligned as well?

 

Developer
tiandi79
Posts: 110
Registered: ‎10-22-2009
My Device: 9700

Re: Editable TextField Alignment

I think u need to write ur own Manager and override sublayout as the following

MyHorizontalFieldManager(LabelField l1, EditField e1) {
...
...
  protected void sublayout( int Width, int Height )
    {
     ...
     setPositionChild(FieldObject, x, y );
    }
}

 

 

Best Regards,
Tiandi
www.tiandiyoyo.com
Visitor
lcw1987565
Posts: 1
Registered: ‎11-09-2010
My Device: bb-9700

Re: Editable TextField Alignment

Hi guys!

 

 I have implemented it !

 

 I  used change the padding value and override "movefocus" method,

yes! the implement method is not good ,so I just have implement it ,if you have a good idea ,please let me know . code follow:

 

 

 

package com.flipme.screen;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.TextField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class SignUpScreen extends  MainScreen{
	
   private VerticalFieldManager _listContainer;
   private TextField  _firstNameInpt;
   private LabelField _firstName;
   private Font font = getFont();
   private String _firstLaStr= "First Name";
   private HorizontalFieldManager _firstRowC;
   
   public SignUpScreen(String label) {
     //first row
     _firstName = new LabelField(_firstLaStr);
     _firstNameInpt = new TextField(FOCUSABLE){
          protected int moveFocus(int amount, int status, int time) {
	    // TODO Auto-generated method stub
             this.invalidate();
	    return super.moveFocus(amount, status, time);
	}
      };
    
     _firstNameInpt.setChangeListener(_firstNameChangeLister);    
     _firstRowC= new HorizontalFieldManager(Manager.USE_ALL_WIDTH);
     _firstRowC.add(_firstName);
     _firstRowC.add(_firstNameInpt);
	     
     _listContainer=new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
     _listContainer.add(_firstRowC);
		
     add(_listContainer);
   }
	
   private int getRightField_x(int HW,int l_MW,int sg_W){
    /*Dialog.alert  ("margin:"+HW+",leftLableWidth:"+l_MW+",textFieldValueWidth:"+sg_W);
     |-------------------------------------------------|
     |       First Name           textfieldValue       |
     |-------------------------------------------------|
     |<-HW->|<- l_MW ->|          |<--  sg_W -->|<-HW->|
     HW is margin-left and margin-right value;
     l_MW is lable text with;
     sg_W is textfield's text width;
    */
     
     int allW 	 = Display.getWidth();
     int centerB_W = allW-HW*2-l_MW-sg_W;
     
     return centerB_W;
   }
	
   private FieldChangeListener _firstNameChangeLister = new  FieldChangeListener() {
        public void fieldChanged(Field field, int context) {
       	   // TODO Auto-generated method stub
    	 int _firNaX = getRightField_x(10,font.getAdvance(_firstLaStr),font.getAdvance(_firstNameInpt.getText()));
	
          _firstNameInpt.setPadding(0, 0, 0, _firNaX);
          
         }
   };
	
   public boolean onClose() {		
       return super.onClose();
   };
}