2012-08-01 29 views
0

我開發一個應用程序中,我需要call at particular phone number的,我有采取LableFieldNumber.setChangeListener(this);並執行其方法fieldChanged並試圖處理事件,但我不能能與此lablefield問題與onClickListner與LableField黑莓

這裏是代碼::

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"); 

     } 

    } 
} 

回答

3

試試這個 -

 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); 
0

您需要實現的方法navigationClickLabelField

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