07-05-2011 04:15 PM
I'm new to application development; and I mean very new. I'm however trying to do something a bit unorthodox. What I want to do is create a screen three buttons (Top, middle and bottom). Then I want the following action to be performed: When a button is pressed, I want the screen to pan in a particular direction. I need help ASAP, please. And I'm not really a fan for copying and pasting code. So an explanation would be much appreciated. But if not, I'll take what I get.
Thanks in advance.
Solved! Go to Solution.
07-05-2011 08:36 PM
Take a look at Manager.setVerticalScroll method. Since any Screen (and MainScreen in particular - are you using that?) is a Manager, the method is available there. To find out the full (not just visible) Screen height, use getVirtualHeight.
07-06-2011 03:45 PM
07-06-2011 05:17 PM
Buttons are generally associated with FieldChangeListeners (many people skip that and override navigationClick instead), but yes, you can put a call to your screen's setVerticalScroll in fieldChanged method of the FieldChangeListener. Read the documentation for ButtonField - there is a decent example of using FieldChangeListener with it. You can associate the same listener with different buttons and then use fieldChanged's field parameter to distinguish between them.
As an aside - create your ButtonFields with NEVER_DIRTY and CONSUME_CLICK style bits - it will save you a lot of headache.
07-08-2011 10:56 AM
07-08-2011 12:34 PM
When you create a ButtonField, create it like this:
ButtonField myButton = new ButtonField("button text", ButtonField.CONSUME_CLICK | ButtonField.NEVER_DIRTY);
Take a look at the API documentation for ButtonClick.
As for why they are important:
CONSUME_CLICK prevents a menu popping up after you click a button. NEVER_DIRTY means the button will not be marked as "dirty" when clicked - important if you are using MainScreen. Read more here:
07-08-2011 03:37 PM
07-08-2011 04:08 PM
You don't have to implement setVerticalScroll - you use the one that already exists. setVerticalScroll(0) brings you to the top of your VerticalFieldManager, setVerticalScroll(getVirtualHeight() - getVisibleHeight()) brings to the bottom, etc.
If you are working only with OS 6.0 and higher, you can use the second form of that method - setVerticalScroll(int position, boolean animate).
Make sure your manager (or screen) has VERTICAL_SCROLL style bit set. For example:
VerticalFieldManager myVfm = new VerticalFieldManager(VerticalFieldManager.VERTICAL
07-09-2011 08:45 PM
07-10-2011 07:29 PM
Rather change position (scroll, pan - however you call it)