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

问题描述

我开发一个应用程序中,我需要在特定的电话号码的来电对,我有采取 LableField Number.setChangeListener(本); 并执行其方法 fieldChanged ,并尝试处理事件,但我不能能与此做 lablefield

这里是code:

 进口net.rim.blackberry.api.invoke.Invoke;
进口net.rim.blackberry.api.invoke.PhoneArguments;
进口net.rim.device.api.system.Bitmap;
进口net.rim.device.api.system.Display;
进口net.rim.device.api.ui.Color;
进口net.rim.device.api.ui.Field;
进口net.rim.device.api.ui.FieldChangeListener;
进口net.rim.device.api.ui.Font;
进口net.rim.device.api.ui.FontFamily;
进口net.rim.device.api.ui.Graphics;
进口net.rim.device.api.ui.component.BitmapField;
进口net.rim.device.api.ui.component.Dialog;
进口net.rim.device.api.ui.component.LabelField;
进口net.rim.device.api.ui.component.NullField;
进口net.rim.device.api.ui.container.Horizo​​ntalFieldManager;
进口net.rim.device.api.ui.container.MainScreen;
进口net.rim.device.api.ui.container.VerticalFieldManager;
进口net.rim.device.api.ui.decor.BackgroundFactory;公共类AboutM1扩展MainScreen实现FieldChangeListener {    VerticalFieldManager TOPVFM,DescriptionVFM,BottomVFM;
    Horizo​​ntalFieldManager TOPHFM,CallHFM,EmailHFM,VIsitUsHFM;    的labelField toplable,说明,广告描述,数量,愈伤组织,电子邮件,EMAILID,Visitus,VisitLink;    位图logom1;
    BitmapField imgField;    公共AboutM1(){        ((VerticalFieldManager)getMainManager())
                .setBackground(BackgroundFactory
                        .createSolidBackground(0xEDEDED));         TOPVFM =新VerticalFieldManager(USE_ALL_WIDTH);
         TOPHFM =新Horizo​​ntalFieldManager(
                FIELD_HCENTER | FIELD_VCENTER);
         AllBITMAPDeclaration();         toplable =新的LabelField(\\ n欢迎来到,FIELD_BOTTOM){
            公共无效漆(图形G){
                g.setBackgroundColor(0xECECEC);
                g.fillRect(0,0,的getWidth(),的getHeight());
                g.setColor(Color.RED);                g.clear();
                super.paint(G);
            }
        };        的FontFamily fontFamily中[] = FontFamily.getFontFamilies();
        字体的字体= fontFamily中[1] .getFont(FontFamily.CBTF_FONT,20);
        字体= fontFamily中[1] .getFont(Font.BOLD,25);
        toplable.setFont(字体);
         imgField =新BitmapField(logom1,FIELD_BOTTOM);        TOPHFM.add(toplable);
        TOPHFM.add(imgField);        TOPVFM.add(TOPHFM);
        加(TOPVFM);
        莱恩的LabelField =新的LabelField(
                _______________________________________){
            保护无效漆(图形G){
                g.setColor(0x324F85);
                super.paint(G);
            }        };        加(绿线);         DescriptionVFM =新VerticalFieldManager(
                VERTICAL_SCROLL);
         说明=新的LabelField(
                \\ nasdasdasd张大SD ASD一个SD reert儿之三T E,
                USE_ALL_WIDTH);
         说明2 =新的LabelField(
                \\ n \\ n公司简介\\ n对于客户关怀\\ n \\ n);
        / *
         *添加(说明);加(说明2);
         * /        DescriptionVFM.add(说明);
        DescriptionVFM.add(新NullField(NullField.FOCUSABLE));
        DescriptionVFM.add(说明2);
        / ******************************底部区域***************** ******** /         BottomVFM =新VerticalFieldManager(USE_ALL_WIDTH);
            CallHFM =新Horizo​​ntalFieldManager(
                FIELD_VCENTER);
             痂=新的LabelField(呼叫,FIELD_VCENTER);
            数=新的LabelField(+ 91-79-30487400,FIELD_VCENTER){
            保护无效漆(图形G){
                g.setColor(0x324F85);                // g.fillRoundRect(0,0,50,5,7,7);
                super.paint(G);
            }            };
            字体= fontFamily中[2] .getFont(Font.BOLD,18);
            Number.setFont(字体);            CallHFM.add(愈伤组织);
            CallHFM.add(号码);
            Number.setChangeListener(本);            EmailHFM =新Horizo​​ntalFieldManager(FIELD_VCENTER);
             电子邮件=新的LabelField(电子邮件:FIELD_VCENTER);
             EMAILID =新的LabelField([email protected],FIELD_VCENTER){
                保护无效漆(图形G){
                    g.setColor(0x324F85);
                    super.paint(G);
                    }
                };                EmailID.setFont(字体);
                EmailID.setChangeListener(本);
                EmailHFM.add(电子邮件);
                EmailHFM.add(EMAILID);             VIsitUsHFM =新Horizo​​ntalFieldManager(FIELD_VCENTER);
             Visitus =新的LabelField(访问我们的网站:FIELD_VCENTER);
             VisitLink =新的LabelField(www.asdasd.com,FIELD_VCENTER){
                保护无效漆(图形G){
                    g.setColor(0x324F85);
                    super.paint(G);
                    }
                };                VisitLink.setFont(字体);
                VisitLink.setChangeListener(本);
                VIsitUsHFM.add(Visitus);
                VIsitUsHFM.add(VisitLink);
        BottomVFM.add(CallHFM);
        BottomVFM.add(EmailHFM);
        BottomVFM.add(VIsitUsHFM);        //添加(BottomVFM);
        DescriptionVFM.add(BottomVFM);
        / ********************************* END BOTTOM ************** ********************************** /
        加(DescriptionVFM);    }    私人无效AllBITMAPDeclaration(){
        // TODO自动生成方法存根
        logom1 = Bitmap.getBitma $ P $的PSource(logo36X36.png);
    }    公共无效fieldChanged(场场,诠释上下文){
        // TODO自动生成方法存根
        如果(场数==)
        {
            Dialog.alert(asdasd);
             / * PhoneArguments参数=新PhoneArguments(PhoneArguments.ARG_CALL,180065449877);
              Invoke.invokeApplication(Invoke.APP_TYPE_PHONE,参数); * /
        }
        如果(场== EMAILID)
        {
            Dialog.alert(asdasd);
        }
        如果(场== VisitLink)
        {
            Dialog.alert(asdasd);        }    }
}


解决方案

试试这个 -

 总数的LabelField =新的LabelField(+ 91-79-30345487400a5675675676,FIELD_VCENTER | Field.FOCUSABLE){
        保护无效漆(图形G){
            g.setColor(0x324F85);            // g.fillRoundRect(0,0,50,5,7,7);
            super.paint(G);
        }
        保护布尔navigationClick(INT的地位,诠释时间){
           Dialog.alert(点击);
            返回super.navigationClick(状态,时间);
        }
        };
        加号码);

I am developing one app in which i need to call at particular phone number for that i have take LableField and make Number.setChangeListener(this); and implement its method fieldChanged and try to handle event but i cant able to do it with this lablefield

Here is code ::

import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.PhoneArguments;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
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.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class AboutM1 extends MainScreen implements FieldChangeListener {

    VerticalFieldManager TOPVFM , DescriptionVFM,BottomVFM;
    HorizontalFieldManager TOPHFM,CallHFM,EmailHFM,VIsitUsHFM ;

    LabelField toplable,Description,Description2,Number,callus,Email,EmailID,Visitus,VisitLink;

    Bitmap logom1;
    BitmapField imgField;

    public AboutM1() {

        ((VerticalFieldManager) getMainManager())
                .setBackground(BackgroundFactory
                        .createSolidBackground(0xEDEDED));

         TOPVFM = new VerticalFieldManager(USE_ALL_WIDTH);
         TOPHFM = new HorizontalFieldManager(
                FIELD_HCENTER | FIELD_VCENTER);


         AllBITMAPDeclaration();

         toplable = new LabelField("\n Welcome to", FIELD_BOTTOM) {
            public void paint(Graphics g) {
                g.setBackgroundColor(0xECECEC);
                g.fillRect(0, 0, getWidth(), getHeight());
                g.setColor(Color.RED);

                g.clear();
                super.paint(g);
            }
        };

        FontFamily fontFamily[] = FontFamily.getFontFamilies();
        Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 20);
        font = fontFamily[1].getFont(Font.BOLD, 25);
        toplable.setFont(font);


         imgField = new BitmapField(logom1, FIELD_BOTTOM);

        TOPHFM.add(toplable);
        TOPHFM.add(imgField);

        TOPVFM.add(TOPHFM);


        add(TOPVFM);
        LabelField Greenline = new LabelField(
                "_______________________________________") {
            protected void paint(Graphics g) {
                g.setColor(0x324F85);
                super.paint(g);
            }

        };

        add(Greenline);

         DescriptionVFM = new VerticalFieldManager(
                VERTICAL_SCROLL);
         Description = new LabelField(
                "\nasdasdasd  as da sd asd a sd reert er ter t e",
                USE_ALL_WIDTH);
         Description2 = new LabelField(
                "\n\n About Us \n For customer care \n\n");
        /*
         * add(Description); add(Description2);
         */

        DescriptionVFM.add(Description);
        DescriptionVFM.add(new NullField(NullField.FOCUSABLE));
        DescriptionVFM.add(Description2);


        /******************************Bottom Area******************************************/

         BottomVFM = new VerticalFieldManager(USE_ALL_WIDTH );
            CallHFM = new HorizontalFieldManager(
                FIELD_VCENTER);
             callus = new LabelField("Call: ", FIELD_VCENTER);
            Number = new LabelField("+91-79-30487400", FIELD_VCENTER) {


            protected void paint(Graphics g) {
                g.setColor(0x324F85);

                // g.fillRoundRect(0, 0, 50, 5, 7, 7);
                super.paint(g);
            }

            };
            font = fontFamily[2].getFont(Font.BOLD, 18);
            Number.setFont(font);

            CallHFM.add(callus);
            CallHFM.add(Number);
            Number.setChangeListener(this);

            EmailHFM = new  HorizontalFieldManager(FIELD_VCENTER);
             Email = new LabelField("Email: ", FIELD_VCENTER);
             EmailID = new LabelField("[email protected]", FIELD_VCENTER) {
                protected void paint(Graphics g) {
                    g.setColor(0x324F85);
                    super.paint(g);
                    }
                };

                EmailID.setFont(font);
                EmailID.setChangeListener(this);
                EmailHFM.add(Email);
                EmailHFM.add(EmailID);

             VIsitUsHFM = new  HorizontalFieldManager(FIELD_VCENTER);
             Visitus = new LabelField("Visit us at: ", FIELD_VCENTER);
             VisitLink = new LabelField("www.asdasd.com", FIELD_VCENTER) {
                protected void paint(Graphics g) {
                    g.setColor(0x324F85);
                    super.paint(g);
                    }
                };

                VisitLink.setFont(font);
                VisitLink.setChangeListener(this);
                VIsitUsHFM.add(Visitus);
                VIsitUsHFM.add(VisitLink);


        BottomVFM.add(CallHFM);
        BottomVFM.add(EmailHFM);
        BottomVFM.add(VIsitUsHFM);

        // add(BottomVFM);
        DescriptionVFM.add(BottomVFM);


        /********************************* END BOTTOM ************************************************/
        add(DescriptionVFM);

    }

    private void AllBITMAPDeclaration() {
        // TODO Auto-generated method stub
        logom1 = Bitmap.getBitmapResource("logo36X36.png");
    }

    public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub
        if(field == Number )
        {
            Dialog.alert("asdasd");
             /* PhoneArguments arguments = new PhoneArguments(PhoneArguments.ARG_CALL, "180065449877"); 
              Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, arguments);*/
        }
        if(field == EmailID)
        {
            Dialog.alert("asdasd");
        }
        if(field == VisitLink)
        {
            Dialog.alert("asdasd");

        }

    }
}
解决方案

try this -

        LabelField  Number = new LabelField("+91-79-30345487400a5675675676", FIELD_VCENTER|Field.FOCUSABLE) {
        protected void paint(Graphics g) {
            g.setColor(0x324F85);

            // g.fillRoundRect(0, 0, 50, 5, 7, 7);
            super.paint(g);
        }
        protected boolean navigationClick(int status, int time) {
           Dialog.alert("clicked");
            return super.navigationClick(status, time);
        }


        };
        add(Number);

这篇关于问题与onClickListner与LableField黑莓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 04:04