关于CustomButtonField在黑莓 [英] About CustomButtonField in blackberry

查看:246
本文介绍了关于CustomButtonField在黑莓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假如我有一个custombuttonField其中包含2位图图片,​​说的2箭头(一个在左边,另一个在右边),当这个用户点击按钮的箭头的颜色应该成为我的应用程序红色。我米推在同一屏幕上点击evevt这样做。我米使用int变量的 pic_status 确定哪些图片在custombutonfield被装上调用 pushScreen()。有什么办法来更新customButtonField(更新位图)在同一个画面不调用pushScreen()。

Suppose I had a custombuttonField which contains 2 bitmap pictures, say 2 arrows(one in left and the other in right) and when the user clicks on this button the color of the arrow should become red in my application. I m doing this by pushing the same screen on click evevt. I m using a int variable pic_status which determines which picture should be loaded on the custombutonfield on calling the pushScreen(). Is there any way to update the customButtonField (update the bitmap) from the same screen without calling pushScreen().

    public void fieldChanged(Field field, int context) 
{
    if(field == bf1)
    {

      if(pic_status == 0)
       {
           b =1;


       }
      UiApplication.getUiApplication().pushScreen(new Screen2(b));    


  }

在我上面的code u必须看到,读音字推相同的屏幕,如果用户点击
按钮。 PLZ给code,而不调用pushScreen更新它()。

In my above code u have seen that i m pushing the same screen if the user clicks the button. Plz give the code to update it without calling pushScreen().

推荐答案

下面code为customButtonField其中有两个图像。一个用于正常图像的聚焦图像和其他

Below code for the customButtonField which have a two image. One for the focus image and other for the normal image.

更新按钮图像,你只需要调用setBitmap方法正常图像。
您可以根据您修改低于code。您需要调用setBitmap方法之后调用invalidate()方法。

to update the button image, you just need to call setBitmap method for normal image. You can modify below code according to you. You need to call invalidate() method after calling the setBitmap method.

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;

class BitmapButtonField extends BitmapField 
{
    Bitmap mNormal;
    Bitmap mFocused;
    String text;
    int mWidth;
    int mHeight;
    public Bitmap bitmap = null;

    public BitmapButtonField(String text,Bitmap normal, Bitmap focused)
    {
        super(normal,FOCUSABLE);
        mNormal = normal;
        mFocused = focused;
        mWidth = mNormal.getWidth();
        mHeight = mNormal.getHeight();
        this.text=text;
        setMargin(0, 0, 0, 0);
        setPadding(0, 0, 0, 0);
    }
    public void setBitmap(Bitmap bitmap)
    {
        mNormal=bitmap;

        this.bitmap=bitmap;
    }
    public void setfocusBitmap(Bitmap bitmap)
    {
        mFocused=bitmap;
    }
    public String getText()
    {
        return text;
    }
    public void setText(String text)
    {
        this.text=text;
    }
    protected void paint(Graphics graphics) {
        Bitmap bitmap = mNormal;
        if(isFocus())
        {
             bitmap = mFocused;
        }
        else
        {
            bitmap = mNormal;
        }

        graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
                        bitmap, 0, 0);
        LabelField l=new LabelField(text);

        graphics.drawText(text,  bitmap.getWidth()/2-l.getPreferredWidth()/2+3,  bitmap.getHeight()/2-l.getPreferredHeight()/2);    
    }
    protected void drawFocus(Graphics graphics, boolean on) {
    }
    protected void onFocus(int direction) {
        invalidate();
        super.onFocus(direction);
    }
    protected void onUnfocus() {
        invalidate();
        super.onUnfocus();
    }
    public int getPreferredWidth() {
        return mWidth;
    }

    public int getPreferredHeight() {
        return mHeight;
    }

    protected void layout(int width, int height) {
        setExtent(mWidth, mHeight);
    }
}

这篇关于关于CustomButtonField在黑莓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆