2011-02-24 2 views

Répondre

0

Dans Blackberry, vous pouvez créer un composant personnalisé en étendant à partir de champs

public class MyField extends Field { 
     public void layout(int width, int height){ 
      setExtent(width, height); //set the field size 
     } 
     public void pain(Graphics g){ 
      //do your own paint here 
      //g.drawText ("Test", 0, 0); 
     } 
    } 

au cas où vous voulez créer se compose d'un LabelField et TextField, je vous suggère de prolonger de TextField

public class InputField extends TextField { 
     private String _label; 
     private TextField _text; 
     public InputField(String label){ 
      _label = label; 
     } 

     public void layout(int width, int height){ 
      setExtend(width + 200, height); //just an example, i add 200 pixel for width 
      //you can get the width of the _label too 
      //need other functions to get width based on the String 
     }   

     //you override how to paint in screen 
     public void paint(Graphics g){ 
      super.paint(g); 
      g.drawText (getLeft()-200, getTop(), _label);        
     } 
    } 

Voir plus d'exemples ici http://supportforums.blackberry.com/t5/Java-Development/Custom-Control/td-p/159699

Questions connexes