04-10-2010 10:37 PM - edited 04-10-2010 10:39 PM
Hey guys, Is there any way to update all the LabelFields values at the same time.
Basically I'm developing a Cricket Scoring program, and everytime a ball gets bowled I want to update the screen with the new stats (which are being displayed using labelfields). The only way I can think of is labelfield.setText(blah) but that is doing them one at a time at has some weird affects on the layout of my screen, causing it to stretch to the right.
Edit: Im using API 5, and the 9700 simulator if that makes a difference.
Any help would be much appreciated
Regards
Solved! Go to Solution.
04-11-2010 12:37 PM - edited 04-11-2010 12:38 PM
Well there really is no way to do it "all at once" since everything is done in sequential order of process.
Given that you are using LabelFields, your best option might be to call on setText. Another way to do it is to use direct drawing, update your stats then call a repaint which would update everything on the screen at once since the whole screen is refreshed at that time.
It is a bit more complicated but it might give the effect that you want.
04-11-2010 02:12 PM - edited 04-11-2010 05:12 PM
Hi JCarty thanks for your suggestion. Unfortunately repaint() doesn't do the trick.
Whenever i setText to the labelFields which are being changed it causes them to Stretch. Been head stretching for the last 24 as to why but can't for the life of me figure out why.
I've attached a screen shots to show what i mean.
If you look at the picture on the right, you can see that the columns are slowing being pushed off the right edge of the screen. Thats after about 12 setText method calls.

Just to give you the layout of my labelfields, they are being stored in a GridManager, 3 rows, 5 columns. I'm guessing the gridmanager is to blame for the behaviour as the FieldManagers below aren't affected.
If there are other methods to dispay the stats im open to suggestions, ie methods that dont involve labelFields.
Thanks for your help.
Regards
Edit: Just done some more playing around and it doesn't do this if i dont set the gridColumnSize to a fixed width. If anyone knows why this is/ how to fix it i would be very grateful ![]()
04-11-2010 05:17 PM
Which GridManager are you using?
LabelField is a bit different in that it will adjust its size and might cause a relayout of the Manager, but I would have thought that should not cause the effect that you see.
I take it you are doing something like this:
synchronized(Application.getEventLock()) {
... update all the labels together at one
}
each time you get new data to update the Screen with?
04-11-2010 05:47 PM
Im using GridFieldManager, then setting the column properties to their sizes.
I did some tests and everytime i updated the labels. the width of each column was being increased by 2px. Regardless of whether the actual value change.
Just changed one of the variables to a RichTextField instead of a label field and it seems to have done the trick. So it probably was the LabelFields, if thats the case i'll just switch them to RichTextFields. I hate it when the solutions are so simple, makes me feel silly!
I wasn't using the method synchronized(Application.getEventLock()), what does this actually do? I read the description in the api, but still dont totally understand.
Thank you Peter and JCarty for your help. It is much appreciated.
04-11-2010 06:10 PM
Re getEventLock().
Only one Thread is allowed to update the screen at one time, this is managed using the Event Lock..
So when you are updating the screen, you usually
a) Run on the EventThread (which gets the Event Lock for you), because you are updating it as a result of some user action (like a key press)
b) Schedule the update to run on the Event Thread at some stage, using
UiApplication.getUiApplication().invokeLater()
c) Schedule the update to run on the Event Thread and wait for it to happen, using
UiApplication.getUiApplication().invokeAndWait()
d) Grab the lock and do the update yourself, using getEventLock.
If you are not doing (a), which I presume you are not since you are responding to some network activity, then you need to choose one of (b), (c) or (d). In your case, when you are making a few small updates, then I think you are OK using (d), which is probably the most efficient way of doing it.
04-11-2010 06:25 PM
OK Thanks for the explanation, was very clear. I'm not great with threads (must have slept thru that month of lectures)
Regards
04-14-2010 09:01 PM - edited 04-14-2010 09:02 PM
Hey i know i've marked this as solved but its randomly started the stretching thing with some inputs.
If anyone has any ideas as to why/what that would be great
. (It also does it with RichTextFields).
Regards
04-14-2010 11:25 PM
It would kinda help if we could see some code.
04-14-2010 11:35 PM - edited 04-14-2010 11:40 PM
gridBowling2 = new GridFieldManager(1,7,GridFieldManager.FIXED_SIZE); gridBowling2.setColumnProperty(0, GridFieldManager.FIXED_SIZE, 210); gridBowling2.setColumnProperty(1, GridFieldManager.FIXED_SIZE, 46); gridBowling2.setColumnProperty(2, GridFieldManager.FIXED_SIZE, 53); gridBowling2.setColumnProperty(3, GridFieldManager.FIXED_SIZE, 38); gridBowling2.setColumnProperty(4, GridFieldManager.FIXED_SIZE, 38); gridBowling2.setColumnProperty(5, GridFieldManager.FIXED_SIZE, 38); gridBowling2.setColumnProperty(6, GridFieldManager.FIXED_SIZE, 42boName1
.setText((bowl1.getName()));boEx1.setText(bowl1.getCurrentBowling().getExtras());BoO1.setText(bowl1.getCurrentBowling().getNoOvers());boM1.setText("m");boR1.setText(Integer.toString(bowl1.getCurrentBowling().getRuns()));boW1.setText(Integer.toString(bowl1.getCurrentBowling().getWickets()));boEc1.setText(Double.toString((bowl1.getCurrentBowling().getEcon())));
gridBowling2.insert(boName1, 0, 0, Field.FIELD_LEFT); gridBowling2.insert(boEx1, 0, 1); gridBowling2.insert(BoO1, 0, 2); gridBowling2.insert(boM1, 0, 3); gridBowling2.insert(boR1, 0, 4); gridBowling2.insert(boW1, 0, 5); gridBowling2.insert(boEc1, 0, 6);
Here are some code snippets from one of the GridFieldManagers which are getting streched out.