04-04-2012 05:36 AM
I created a screen in my app and i need it to scroll otherwise I can't fit everything on the screen, however I can't get anything to scroll unless I create some kind of list. I created simple test to illustrate what I ma trying to do, you can see below all I do is cretae 50 labels which will exceed the screen length (Bold 9900) and I expect it would show a scroll bar and/or let me scroll down, but i have no scroll bar and cannot scroll at all.
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.*;
public final class TestScreen extends MainScreen
{
public TestScreen()
{
super(FullScreen.NO_VERTICAL_SCROLL | FullScreen.VERTICAL_SCROLLBAR);
final VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
for (int i=0; i<50;i++){
add(new RichTextField("Line " + String.valueOf(i)));
}
add(vfm);
}
}
Solved! Go to Solution.
04-04-2012 05:45 AM
04-04-2012 05:47 AM - edited 04-04-2012 05:51 AM
I notice what ppears to be some inconsistencies in the style flags you have used:
1) super(FullScreen.NO_VERTICAL_SCROLL | FullScreen.VERTICAL_SCROLLBAR);
You are extending MainScreen, so you should use MainScreen style flags here. Also If you have told the Screen, that there is no vertical scroll, why would it need to have a scroll bar?
I would remove these completely.
2) final VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_HEIGHT | VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
Use all height is telling the Manager to use the whoel screen height. I don't think you need to do this, so I would remove it. And as the other are the default actions, then I would remove then as well.
What I am basically saying is that if you remove all your style indicators, it should work as you require.
One final thing though, be aware that Fields must be focusable to facilitate scrolling. I beleive RichTextFields are focusable by default, so this should not be a problem. But you might want to try forcing it with:
add(new RichTextField("Line " + String.valueOf(i), RichTextField.FOCUSABLE));
Hope this helps.
Edit:
Just to expand on Simon's points:
1) you could add the Fields directly, but the approach you are taking should work too.
2) in my experience, AddAll has better performance once the screen has been displayed as it reduces the interaction with displayed screen. In this case, when the screen is just being constructed, it should no impact.
04-04-2012 05:53 AM - edited 04-04-2012 05:53 AM
Try like this sample code:
public class SimpleScreen extends MainScreen
{
VerticalFieldManager vertical;
Font font;
public SimpleScreen()
{
font=Font.getDefault().derive(Font.ITALIC|Font.BOL D, 20);
createGUI();
this.setFont(font);
}
private void createGUI()
{
vertical=new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
for(int i=0;i<30;i++)
vertical.add(new LabelField("Label: "+(i+1), Field.FIELD_HCENTER|Field.FOCUSABLE));
add(vertical);
}
}
04-04-2012 06:14 AM
Thanks Simon,
Yes that was a stupid error in my sample. Also thanks for the tip regarding performance.
My real issue is that if a create a vfm, I can add fields to the screen above the vfm but if I add a tableview to the vfm that works perfectly without the vfm, but if I add it to the vfm I will always get an IllegalState exception
Is there some limitation that won't allow me to add a tableview to a vfm?
04-04-2012 06:18 AM
Since that is nothing like the Subject of this Thread, I suggest you mark this Thread as solved, and start a new Thread that actually refects the problem you are reporting. And I have to wonder why you asked this question in the first place!
04-04-2012 06:25 AM
Thanks Peter,
I see your point about the flags, I'll take that on board. Also your point about the performance about addAll seems to be correct, I have no performance difference in this example.
To be honest I can't fine anything that tells me what the USE_ALL_HEIGHT does, just trying to get it working, I guess it means to use the maximum scrollable size of the virtual screen. I removed it and now it's working better by only scrolling to the maximum used screen. Much better
04-04-2012 06:29 AM
The documentation of the style flags is sparse I agree, and in fact in some cases the flags have different effects in different places. Sorry I can't point you at anything that will help. Experience does!
The contributor to this KB article, that I recommend you review, seems to understand these better than most.
http://supportforums.blackberry.com/t5/Java-Develo