本文介绍了BitmapField点击不会对黑莓应用工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安排7 bimapfield水平,如果我点击bitmapfield它要推另一屏幕下面是我的code,但余did't得到另一个屏幕任何一个可以帮助我什么是错在这code

  BitmapField bitmap1 =新BitmapField(
    Bitmap.getBitma $ P $的PSource(profile_n.png),可聚焦| DrawStyle.HCENTER)
{
    保护无效的onfocus(INT方向)
    {
        rollno = 1;
        。this.getScreen()无效();
    }
    保护无效onUnfocus()
    {    }
    保护布尔navigationClick(INT的地位,诠释时间){
           。UiApplication.getUiApplication()popScreen(getScreen());
            。UiApplication.getUiApplication()pushScreen(新AccMainScreen());
        返回true;
    }
};


解决方案

您可以使用容纳图像的自定义字段,并像一个按钮,而不是bitmapfield。
这里是code,我建议:

 进口net.rim.device.api.system.Bitmap;
进口net.rim.device.api.ui.Field;
进口net.rim.device.api.ui.Graphics;
公共类的CustomButton扩展字段{    保护位图的图标;
    保护INT fieldWidth;
    保护INT fieldHeight;    公众的CustomButton(字符串iconSource,长样式){
        超(样式);
        图标= Bitmap.getBitma $ P $的PSource(iconSource);
        fieldHeight = icon.getHeight();
        fieldWidth = icon.getWidth();
    }    公众诠释的get preferredWidth(){
        返回fieldWidth;
    }    公众诠释的get preferredHeight(){
        返回fieldHeight;
    }
    保护无效布局(INT为arg0,ARG1 INT){
        setExtent(GET preferredWidth(),获得preferredHeight());
    }
    保护无效DRAWFOCUS(图形显卡,布尔){}    保护无效漆(图形图像){
        graphics.fillRect(0,0,fieldWidth,fieldHeight);
        graphics.drawBitmap(0,0,fieldWidth,fieldHeight,图标,0,0);
    }
    保护布尔navigationClick(INT的地位,诠释时间){
        fieldChangeNotify(0);
        返回true;
    }
}

您可以使用该按钮就像一个默认的按钮,并通过使用setChangeListener功能改变它的听众。

 的CustomButton A按钮=新的CustomButton(图形/ someIcon.png);
aButton.setChangeListener(新FieldChangeListener(){
    公共无效fieldChanged(场场,诠释上下文){
        。UiApplication.getUiApplication()popScreen(getScreen());
        。UiApplication.getUiApplication()pushScreen(新AccMainScreen());
    }
});

i arranged 7 bimapfield in horizontal if i click the bitmapfield it want to push the another screen Here is my code but i did't get the another screen can any one help me whats wrong in this code

BitmapField bitmap1 = new BitmapField(
    Bitmap.getBitmapResource("profile_n.png"),FOCUSABLE | DrawStyle.HCENTER)
{
    protected void onFocus(int direction)
    {
        rollno=1;
        this.getScreen().invalidate();
    }
    protected void onUnfocus()
    {

    }   
    protected boolean navigationClick(int status, int time){
           UiApplication.getUiApplication().popScreen(getScreen());
            UiApplication.getUiApplication().pushScreen(new AccMainScreen());
        return true;
    }
};
解决方案

You can use a custom field that hold a image and behave like a button instead of bitmapfield.Here is the code i suggest:

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class CustomButton extends Field{

    protected Bitmap icon;
    protected int fieldWidth;
    protected int fieldHeight;

    public CustomButton (String iconSource,long style) {
        super(style);
        icon = Bitmap.getBitmapResource(iconSource);
        fieldHeight = icon.getHeight();
        fieldWidth = icon.getWidth();
    }

    public int getPreferredWidth() {
        return fieldWidth;
    }

    public int getPreferredHeight() {
        return fieldHeight;
    }
    protected void layout(int arg0, int arg1) {
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
    protected void drawFocus(Graphics graphics, boolean on){ }

    protected void paint(Graphics graphics) {
        graphics.fillRect(0, 0, fieldWidth, fieldHeight);
        graphics.drawBitmap(0,0, fieldWidth, fieldHeight, icon, 0, 0);
    }
    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }
}

you can use this button like a default button and change listener of it by using setChangeListener function.

CustomButton aButton = new CustomButton ("graphics/someIcon.png");
aButton.setChangeListener(new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
        UiApplication.getUiApplication().popScreen(getScreen());
        UiApplication.getUiApplication().pushScreen(new AccMainScreen());   
    }
});

这篇关于BitmapField点击不会对黑莓应用工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 08:50