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
Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900
Accepted Solution

Very Strange - LabelField setText in SendListener Only Displaying First Character of String

Am I missing something obvious? Trying to settext on labelfield in sms send listener however the labelfield is only displaying the first character in the string.  If I add a menu or other method to set the labelfield text it works great, just not in send listener.

 

public class SMSScreen extends MainScreen {

	LabelField label1;

	public SMSScreen() {
		label1 = new LabelField("0");
		add(label1);

		smsSendListener smsSL = new smsSendListener();
		SMS.addSendListener(smsSL);
	}

	public class smsSendListener implements SendListener {
		public boolean sendMessage(Message message) {
			synchronized(UiApplication.getEventLock()) {
				label1.setText("1234567890");
			}
			return true;
		}
	}
}

 

When an sms message is sent all the labelfield displays is"1"

 

 

Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

[ Edited ]

More interesting is that if I initially set the labelfield text to a longer string like "99999999999" the correct string is displayed in sendlistener ("1234567890").  Almost seems like a labelfield length issue or just a bug somewhere?  Anyone else get the same results?

Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

Ok.  Something not right.  Even thought the labelfield only displays "1", when I getText() it returns the entire string...

 

	public class smsSendListener implements SendListener {
		public boolean sendMessage(Message message) {
			synchronized(UiApplication.getEventLock()) {
				label1.setText("1234567890");
			}
			
			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
					Dialog.alert(label1.getText());
				} 
			});
			
			return true;
		}
	}

 

Why would the label only display the first character of the string?

Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

Change the labelfield to a textfield and string displays fine.  What is wrong with the labelfield?

Developer
Posts: 16,495
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

is this all there is on the screen? or do you add other components, have a custom layout or something like that?
----------------------------------------------------------
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
Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

[ Edited ]

That's all that is on the screen. Absolutely nothing else. Does this code produce the same issue for you? Even in simulator I get same issue.

Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

Hey Simon.  Do you ge the same results?

Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

Do others get these same results?  Anyone have any insight as to why this is happening?

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

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

Do you have a try/catch around the code setting this Field.  I would put one in and watch for an exception.

 

Also I would be concerned about who owns that Field.  In your listener you might not be running in your own Application, so you could be trying to update one Application's screen from another Application.  If the Field is owned by your Application, then you might want to replace this code with a Global Event firing an Event to your Application.  Then, in your Global Event Listener, you can be sure that the update occurs in the correct application. 

Contributor
Posts: 32
Registered: ‎10-21-2012
My Device: 9900

Re: Very Strange - LabelField setText in SendListener Only Displaying First Character of String

Thank you, Peter. I will give try/catch a shot. In regards to owner, if I replace the label with a textfield the settext works fine.