Editfield滚动无法在黑莓中达到顶峰

时间:2011-10-01 13:06:34

标签: blackberry blackberry-editfield

我在登录表单中有两个EditFields,名称为Email:和Password:。就在电子邮件下面,我有登录按钮。假设我下来直到登录,我只能向后滚动直到密码字段。光标无法到达电子邮件字段。在模拟器中,我尝试使用箭头键和触控板。请帮助如何滚动回第一个编辑区域

AbsoluteFieldManager ab = new AbsoluteFieldManager();

  add(ab);
  new SeparatorField();

     et=new EditField("Email-id:","");
     pwd=new PasswordEditField("Password:",""); 

     ab.add(et,35,110); 
     ab.add(pwd,35,150); 

我正在使用AbsoluteFieldManager并为OS 6.0进行开发。我希望loginscreen看起来像facebook登录页面。 请告诉我可能导致无法向上滚动的原因

4 个答案:

答案 0 :(得分:2)

它也可能是一个RIM错误。你用什么操作系统?是OS 5+吗?您是否对屏幕上的某些UI元素(包括屏幕本身)使用自定义填充/边距/边框?如果是,请尝试注释掉任何设置填充/边距/边框的代码,以检查是否是这种情况。

答案 1 :(得分:2)

可能是 AbsoluteFieldManager 的RIM错误。从来没有使用它,所以我不知道它。您可以创建一个解决此问题的方法。在下面找到它:

et=new EditField("Email-id:","");
pwd=new PasswordEditField("Password:","") {
    protected int moveFocus(int amount, int status, int time) {
        int cursorPosition = this.getCursorPosition();
        if ((cursorPosition == 0) && (amount < 0)) {
            et.setFocus();
            return 0;
        }
        else {
            return super.moveFocus(amount, status, time);
        }
    }
}; 

通过这种方式,当您到达密码编辑字段中的第一个元素时,您将要求电子邮件字段获得关注。这对你来说很有用。

解决问题的另一种方法是在水平字段管理器中添加两个字段,这样我想这对你肯定会有效。如果不使用第一种方法。您可以在下面找到Horizo​​ntalFieldManager的代码:

 et=new EditField("Email-id:","");
 pwd=new PasswordEditField("Password:",""); 
 HorizontalFieldManager manager = new HorizontalFieldManager();
 manager.add(et);
 manager.add(pwd);
 ab.add(manager, yourX, yourY);

答案 2 :(得分:0)

您可以将此代码用于登录页面:

public class loginscreen extends MainScreen implements FieldChangeListener {

private int deviceWidth = Display.getWidth();
private int deviceHeight = Display.getHeight();
private VerticalFieldManager subManager;
private VerticalFieldManager mainManager;
public long mycolor = 0x00FFFFFF;

Screen _screen = home.Screen;
TextField heading = new TextField(Field.NON_FOCUSABLE);

TextField username_ef = new TextField();
PasswordEditField password_ef = new PasswordEditField();
CheckboxField rememberpass = new CheckboxField();   
public ButtonField login_bt = new ButtonField("Login", ButtonField.CONSUME_CLICK);
public ButtonField register_bt = new ButtonField("Register", ButtonField.CONSUME_CLICK);

public loginscreen()
{
    super();
    final Bitmap backgroundBitmap = Bitmap.getBitmapResource("bgd.png");

    HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )

    {

    protected void sublayout(int width, int height) 

    {

    Field field;

    int numberOfFields = getFieldCount();

    int x = 245;

    int y = 0;

    for (int i = 0;i < numberOfFields;i++) 

    {

    field = getField(i);

    setPositionChild(field,x,y); 

    layoutChild(field, width, height);

    x +=_screen.getWidth()-381;

    y += 0;//l17

    }

    width=_screen.getWidth();

    height=48;//w19

    setExtent(width, height);

    }

    };


   mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
    {

        public void paint(Graphics graphics)
        {
            graphics.clear();
            graphics.drawBitmap(0, 0, deviceWidth, deviceHeight, backgroundBitmap, 0, 0);                       
            super.paint(graphics);
        }            
    };
  //this manger is used for adding the componentes
    subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
    {
        protected void sublayout( int maxWidth, int maxHeight )
        {
            int displayWidth = deviceWidth;
            int displayHeight = deviceHeight;

            super.sublayout( displayWidth, displayHeight);
            setExtent( displayWidth, displayHeight);
        }

        public void paint(Graphics graphics)

        {
            graphics.setColor((int) mycolor);
        super.paint(graphics);

        }
    }; 


    username_ef.setLabel("Username: ");
    password_ef.setLabel("Password: ");
    rememberpass.setLabel("Remember Password");
    heading.setLabel("Please enter your credentials: ");

    username_ef.setMaxSize(8);
    password_ef.setMaxSize(20);

    subManager.add(heading);
    subManager.add(username_ef);
    subManager.add(password_ef);
    subManager.add(rememberpass);
    subManager.add(new SeparatorField());
    login_bt.setChangeListener(this);   
    register_bt.setChangeListener(this); 

    hfm.add(login_bt);
    hfm.add(register_bt);
    subManager.add(hfm);

    mainManager.add(subManager);
    this.add(mainManager);

}

public boolean onSavePrompt()
{
    return true;
} 


public void fieldChanged(Field field, int context) {
    // TODO Auto-generated method stub 
    if(field == login_bt)
    {
        //do your code for login button click           
    }

    if(field == register_bt)
    {
        //code for register button click
    }
}}

答案 3 :(得分:-2)

您所描述的不是正常行为。

我的结论是您的代码有一个或多个错误,为了解决您的问题,您应该修改代码以修复错误。然后,您就可以在各个字段中向上和向下滚动。

注意:由于这个问题,我不可能对确切的错误做更具体的说明。因此,我将向您展示您所描述的可以正确滚动的布局示例,您可以使用默认值来确定哪些偏差导致了您的错误。

// inside MainScreen constructor
add(new EditField("Username:","",0));
add(new EditField("Password:","",0));
add(new ButtonField(buttonBMP,ButtonField.CONSUME_CLICK));