Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
LTCCTL
Posts: 45
Registered: ‎08-16-2008
My Device: Torch 9800, Bold 9700, Storm 9550, Curve 8520
My Carrier: Airtel

Transferring the content of a EditField to a variable and also show in a label

Hi all,

 

How do we show the content in label while we are typing in an EditField and also let me know how do we transfer the content of an EditField to a variable.

 

Thanks in advance

 

Regards

LTCCTL

Please use plain text.
Developer
simon_hain
Posts: 16,107
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Transferring the content of a EditField to a variable and also show in a label

i would suggest you set a FieldChangeListener to the EditField. use getText and setText on the EditField resp LabelField in the fieldChanged method.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Transferring the content of a EditField to a variable and also show in a label

I think you can call getText() and your editfield shouldn't need any help with display but if you want to

intercept each keystroke and do something, you can. For example,

 

class nocrlf extends EditField
    {
    public nocrlf(String nm, String iv) {super(nm,iv); } 
    protected boolean keyDown(int kc, int time)
    { int kp=Keypad.key(kc);
     char c= Keypad.map(kc);
     if (( c=='\n')||(c=='\r'))
     { fieldChangeNotify(-1); 
     
     return true;}      return super.keyDown(kc,time);
    }
     }

 

I guess it may be interesting to think about, if you wanted to redraw your text using an ad hoc "font" ( or draw pictures unrelated to your typed text, or somekind of dali-esque text like they have for verification on some websites). what

you would do here - presumably you could just invalidate on each keystroke and handle everything in paint.

 

 

 

Please use plain text.
New Developer
LTCCTL
Posts: 45
Registered: ‎08-16-2008
My Device: Torch 9800, Bold 9700, Storm 9550, Curve 8520
My Carrier: Airtel

Re: Transferring the content of a EditField to a variable and also show in a label

Hi all,

 

thanks for your reply, now please let me know one more thing  how to change the font size of the text field.

 

Regards

LTCCTL

 

 

 

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Transferring the content of a EditField to a variable and also show in a label

Use Field.getFont() to retreive the current font, then use Font.derive() to derive a new font based on the default.

 

See the API docs for Field and Font.

 

 

Please use plain text.