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
Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010
My Device: Not Specified
Accepted Solution

Why setFocus() and setText() methods doesn't work for BasicEditField

Hi,

 

I tried to apply setFocus() and setText() methods on a BasicEditField, but it always throws "Illegal state exception".   However, getText() method can work.

Can someone explain this please? Thanks!

Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Why setFocus() and setText() methods doesn't work for BasicEditField

Can you show a code snippet?

 

IlegalState might be that you are trying to access the UI controls from outside of the event thread.

 

 

Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010
My Device: Not Specified

Re: Why setFocus() and setText() methods doesn't work for BasicEditField

Well, I just tried to setText("xxx") after successfully getText().

It this is caused by trying to access the UI controls from outside of the event thread, I just wonder why would getText() worked?

Developer
peter_strange
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Why setFocus() and setText() methods doesn't work for BasicEditField

Because getText does not change the display?.

Developer
KushBB
Posts: 374
Registered: ‎04-07-2010
My Device: Bold 9000

Re: Why setFocus() and setText() methods doesn't work for BasicEditField

One other thing could be if you are using filters on your EditField and you use setText() to set some thing that is not allowed by the filter, it will throw an exception....

Press the Like button (Thumb up) on the left side to thank and
please mark the Thread as solved if its solved...
K.S
Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010
My Device: Not Specified

Re: Why setFocus() and setText() methods doesn't work for BasicEditField

Thanks KushBB, I think this may be the reason.

The BasicEditField is constructed as new BasicEditField(label,data,Integer.MAX_VALUE,r);

I'll try to remove the sytle, and try again.

Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010
My Device: Not Specified

Re: Why setFocus() and setText() methods doesn't work for BasicEditField

Yes, after removing the READONLY style, I can use the setText() now.