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
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later
Accepted Solution

Static Menu Tab on list scroll

I have 4 tabs, and I have a list.The list is scrollable, I want on scrolling tho..the tabs above to remain, and to scroll just thru the list?

 

how can i fix my code?

 

package mypackage;


import java.util.Vector;

import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class TabControl extends MainScreen implements FocusChangeListener {

        private LabelField tab1;

        private LabelField tab2;

        private LabelField tab3;
        
        private LabelField tab4;
        
        private LabelField spacer1;

        private LabelField spacer2;
        
        private LabelField spacer3;

        private VerticalFieldManager tabArea;

        private LabelField tab1Heading;

        private BasicEditField tab1Field1;

        private BasicEditField tab1Field2;
        
       

        private LabelField tab2Heading;

        private BasicEditField tab2Field1;

        private BasicEditField tab2Field2;
        
        

        private LabelField tab3Heading;

        private BasicEditField tab3Field1;

        private BasicEditField tab3Field2;
        
      
        
        private BasicEditField tab4Field1;

        private BasicEditField tab4Field2;
        
        private LabelField tab4Heading;
        
        private VerticalFieldManager tab1Manager;
        private VerticalFieldManager tab2Manager;
        private VerticalFieldManager tab3Manager;
        private VerticalFieldManager tab4Manager;
        private int catId = 0;
        public TabControl(int id) {
        	catId = id;
            HorizontalFieldManager hManager = new HorizontalFieldManager();
            tab1 = new LabelField("Top20", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT);
            tab2 = new LabelField("Artists", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT);
            tab3 = new LabelField("History", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT);
            tab4 = new LabelField("Tab 4", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT);
            spacer1 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
            spacer2 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
            spacer3 = new LabelField(" | ", LabelField.NON_FOCUSABLE);

            tab1.setFocusListener(this);
            tab2.setFocusListener(this);
            tab3.setFocusListener(this);
            tab4.setFocusListener(this);
            hManager.add(tab1);
            hManager.add(spacer1);
            hManager.add(tab2);
            hManager.add(spacer2);
            hManager.add(tab3);
            hManager.add(spacer3);
            hManager.add(tab4);

            add(hManager);
            add(new SeparatorField());
            tab1Manager = new VerticalFieldManager();
            tab2Manager = new VerticalFieldManager();
            tab3Manager = new VerticalFieldManager();
            tab4Manager = new VerticalFieldManager();
            
            tabArea = displayTab1();
            add(tabArea);

        }

        public void focusChanged(Field field, int eventType) {
            if (tabArea != null) {
                if (eventType == FOCUS_GAINED) {
                    if (field == tab1) {
                        System.out.println("Switch to Tab 1");
                        delete(tabArea);
                        tabArea = displayTab1();
                        add(tabArea);
                    } else if (field == tab2) {
                        System.out.println("Switch to Tab 2");
                        System.out.println("Switch to Tab 1");
                        delete(tabArea);
                        tabArea = displayTab2();
                        add(tabArea);
                    } else if (field == tab3) {
                        System.out.println("Switch to Tab 3");
                        System.out.println("Switch to Tab 1");
                        delete(tabArea);
                        tabArea = displayTab3();
                        add(tabArea);
                    }
                    else if (field == tab4) {
                        System.out.println("Switch to Tab 3");
                        System.out.println("Switch to Tab 1");
                        delete(tabArea);
                        tabArea = displayTab4();
                        add(tabArea);
                    }
                }
            }

        }

        public VerticalFieldManager displayTab1() {
        	
        	Vector v0 = new Vector();
        	MAMClient.getTop20(v0, catId);
        	SingersListField listField = new SingersListField(v0);
        	listField.setSelectedIndex(-1);
   		    listField.setSize(v0.size());
   		   
          
   		tab1Manager.deleteAll();
        	tab1Manager.add(listField);
            return tab1Manager;
        }

        public VerticalFieldManager displayTab2() {
            if (tab2Heading == null) {
                tab2Heading = new LabelField("Password Recovery");
                tab2Manager.add(tab2Heading);
            }
            if (tab2Field1 == null) {
                tab2Field1 = new BasicEditField("Security Question: ", "Mother's Maiden Name?");
                tab2Manager.add(tab2Field1);
            }
            if (tab2Field2 == null) {
                tab2Field2 = new BasicEditField("Password: ", "");
                tab2Manager.add(tab2Field2);
            }
            return tab2Manager;
        }

        public VerticalFieldManager displayTab3() {
            if (tab3Heading == null) {
                tab3Heading = new LabelField("Interests");
                tab3Manager.add(tab3Heading);
            }
            if (tab3Field1 == null) {
                tab3Field1 = new BasicEditField("Hobbies: ", "");
                tab3Manager.add(tab3Field1);
            }
            if (tab3Field2 == null) {
                tab3Field2 = new BasicEditField("Memberships: ", "");
                tab3Manager.add(tab3Field2);
            }
            return tab3Manager;
        }
        public VerticalFieldManager displayTab4() {
            if (tab4Heading == null) {
                tab4Heading = new LabelField("Registration");
                tab4Manager.add(tab4Heading);
            }
            if (tab4Field1 == null) {
                tab4Field1 = new BasicEditField("Username: ", "");
                tab4Manager.add(tab4Field1);
            }
            if (tab4Field2 == null) {
                tab4Field2 = new BasicEditField("Password: ", "");
                tab4Manager.add(tab4Field2);
            }
            return tab4Manager;
        }
    }

 

Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Static Menu Tab on list scroll

I am speaking about tab 1 ofcourse
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Static Menu Tab on list scroll

what I need is

have menu bar on the top, on click it opens lists.Those lists are scrollable but the menu should remain on top without moving from its place.any helps?
Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Static Menu Tab on list scroll

you could use setTitle to use the top manager available by default.
see
http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

otherwise you could use a NON_SCROLLABLE manager and use a VerticalFieldManager with SCROLLABLE for your scrollable part.
----------------------------------------------------------
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
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Static Menu Tab on list scroll

HorizontalFieldManager hManager = new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL);


I actually did that, and it didnt work.
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Static Menu Tab on list scroll

I still couldnt solve this
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Static Menu Tab on list scroll

i solved it now

Yes, u do the first horizontalmanager non scrollable and the other scrollable.

but in your screen constructor u need to specify this too
super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);