Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 刷新字段';s州_Blackberry - Fatal编程技术网

Blackberry 刷新字段';s州

Blackberry 刷新字段';s州,blackberry,Blackberry,在我的应用程序中,我使用自定义字段和“set***”方法来更改这些字段的一些参数(例如背景图像)。这一切都很好,只有一个问题:我正在设置和更改此字段的参数,如下所示: record = new UIButton("RECORD", Field.FOCUSABLE, kButtonWidth/3-5, kButtonHeight); vfm2.add(Record); //I tryed this befor setters and after: no different

在我的应用程序中,我使用自定义字段和“set***”方法来更改这些字段的一些参数(例如背景图像)。这一切都很好,只有一个问题:我正在设置和更改此字段的参数,如下所示:

    record = new UIButton("RECORD", Field.FOCUSABLE, kButtonWidth/3-5, kButtonHeight);
    vfm2.add(Record); //I tryed this befor setters and after: no different
    record.setBackgroundImage("buttonDark.png", "buttonDark.png", "buttonDark.png");
    record.setTitleFontSize(Display.getHeight()/40);
    record.setTitle("RECORD");
当按下带有此字段的屏幕时,我的字段看起来没有调用任何setter(但事实是:我通过日志消息检查了这一点)。字段的状态只有在聚焦后才会刷新(我在
onFocus
onnfocus
上调用相同的设置程序,其中有
invalidate()
)。有没有办法在屏幕上重新显示?例如,在iphonesdk中,有一个
viewdideappear
方法,它在视图(屏幕)出现时收集。黑莓手机也有同样的功能吗?还是其他解决方案


这是我的
ui按钮
类代码:

public class UIButton extends Field 
{       
    private String title = null;
    private Font font;
    private int fontSize;
    private int color;
    private int horizontalAligment;
    private int state;  //0 - normal;   1 - focused;    2 - HightLighted;

    private int height;
    private int width;

    private EncodedImage currentPicture;
    private EncodedImage onPicture;
    private EncodedImage offPicture;
    private EncodedImage lightPicture;

    public UIButton(long style, int Widgh, int Height)
    {
        super(style);

        height = Height;
        width = Widgh;
        fontSize = Display.getHeight()/20;
        FontFamily ff = getFont().getFontFamily();
        font = ff.getFont(0, fontSize);
        title = "";
        color = Color.WHITE;
        state = 0;
        horizontalAligment = DrawStyle.HCENTER;

        onPicture = offPicture = lightPicture = EncodedImage.getEncodedImageResource("buttonDark.png");
        currentPicture = offPicture;

    }

    public String getTitle()
    {
        return title;
    }

    public void setTitleColor (int Color) {
        color = Color;
        invalidate();
    }

    public void setFrame (int Height, int Width) {
        height = Height;
        width = Width;
        invalidate();
    }

    public void setTitle (String Title) {
        title = Title;
        invalidate();
    }

    public void setTitleHorizontalAligment (int hAligment) {
        horizontalAligment = hAligment;
        invalidate();
    }

    public void setBackgroundImage (String forStateNurmal, String forStateFocused, String forStateHightlighted) {
        onPicture = EncodedImage.getEncodedImageResource(forStateFocused);
        offPicture = EncodedImage.getEncodedImageResource(forStateNurmal);
        lightPicture = EncodedImage.getEncodedImageResource(forStateHightlighted);
        invalidate();
    }

    public void setState (int State) {
        state = State;
        switch (state) {
        case 0: {
            currentPicture = offPicture;
            invalidate();
            break;
        }
        case 1: {
            currentPicture = onPicture;
            invalidate();
            break;
        }
        case 2: {
            currentPicture = lightPicture;
            invalidate();
            break;
        }
        }
    }

    public void setTitleFont (Font Font) {
        font = Font;
        invalidate();
    }

    public void setTitleFontSize (int FontSize) {
        fontSize = FontSize;
        FontFamily ff = font.getFontFamily();
        font = ff.getFont(0, fontSize);
        invalidate();
    }

    public int getPreferredHeight() 
    {
        return height;
    }

    public int getPreferredWidth() 
    {
        return  width;
    }


    protected void onFocus(int direction) 
    {
        super.onFocus(direction);
        this.setState(0);
    }


    protected void onUnfocus() 
    {
        if (state!=2) this.setState(1);
    }


    protected void drawFocus(Graphics graphics, boolean on) 
    {
        super.drawFocus(graphics, on);
    }


    protected void layout(int width, int height) 
    {
        setExtent(getPreferredWidth(),getPreferredHeight());
    }


    protected void paint(Graphics graphics) 
    {
        ResizeImage r = new ResizeImage();
        currentPicture = r.sizeImage(currentPicture, width-2, height-2);
        graphics.drawBitmap(1, 1, width-2, height-2, currentPicture.getBitmap(), 0, 0);
        if (title.getBytes().length>0) {

            graphics.setColor(color);
            graphics.setFont(font);

            int x = 0;
            if (horizontalAligment == DrawStyle.LEFT) x = 2;
            graphics.drawText(title, x, (height-font.getHeight())/2, 
                    (int)( getStyle() & DrawStyle.VCENTER & horizontalAligment | DrawStyle.HALIGN_MASK ), width );
        }
    }

    protected boolean navigationClick(int status, int time) 
    {
        fieldChangeNotify(1);
        return true;
    }

}

如果在将字段添加到管理器之前调用set**方法,则首先不应出现此问题。是否有在之后调用它们的原因?

如果在将字段添加到管理器之前调用set**方法,则首先不应出现此问题。在Java中,用小写字母命名本地标识符和字段标识符是一种很强的惯例。因此,将“Record”视为局部变量名是相当令人困惑的



如果没有自定义字段UIButton的代码,就不可能在这里回答您的问题。BlackBerry OS的内置组件在这种添加和设置顺序下可以正常工作,因此您的自定义字段在布局和绘制方面可能没有遵循BlackBerry的惯例。

在Java中,使用小写字母命名本地和字段标识符是一种非常强的惯例。因此,将“Record”视为局部变量名是相当令人困惑的



如果没有自定义字段UIButton的代码,就不可能在这里回答您的问题。BlackBerry操作系统的内置组件在这种添加和设置顺序下可以正常工作,因此您的自定义字段在布局和绘制方面可能没有遵循BlackBerry的惯例。

您忘记更改setBackgroundImage()中的currentPicture。尝试
currentPicture=offPicture

或者在
setBackgroundImage()中调用
this.setState(0)
您忘记更改setBackgroundImage()中的currentPicture。尝试
currentPicture=offPicture

或者在
setBackgroundImage()中调用
this.setState(0)

您也可以在Record.setBackgroundImage(“buttonDark.png”、“buttonDark.png”、“buttonDark.png”)之后调用invalidate();tnx请求响应,但这不起作用。请尝试在setBackgroundImage()中调用此.setState(0)。我不确定这是否有助于你在未聚焦状态下改变图像。你是对的。我发现我的
EncodedImage currentPicture
不是指针,所以当我更改其他图像时它没有更改。你能将此作为答案发布吗?我需要批准一些东西:)你也可以在Record.setBackgroundImage(“buttonDark.png”、“buttonDark.png”、“buttonDark.png”)之后调用invalidate();tnx请求响应,但这不起作用。请尝试在setBackgroundImage()中调用此.setState(0)。我不确定这是否有助于你在未聚焦状态下改变图像。你是对的。我发现我的
EncodedImage currentPicture
不是指针,所以当我更改其他图像时它没有更改。你能将此作为答案发布吗?我需要批准一些事情:)我很伤心,我试过前后。没有什么不同。但在这段代码之前,我将vfm2添加到屏幕中。我应该在以后做这个吗?我很伤心,我试过前后。没有什么不同。但在这段代码之前,我将vfm2添加到屏幕中。我应该在以后做这个吗?