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
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Tab Control Problem

I have two tab controls,simply 2 ButtonFields. Below that i have added basicEditField as searchfield .Searching is done within List. When i click on tabs i am changing only data of the ListField.I also want that SearchField should be changed according to the changed tabs.Its not working. I am getting IllegalArgumentException. How to do it?

Regular Contributor
heretocode
Posts: 70
Registered: ‎12-19-2011
My Device: Bold 9780

Re: Tab Control Problem

package com.cls.tab;

import net.rim.device.api.system.Display;
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.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
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 UiApplication {

	public TabControl() {
		TabControlScreen screen = new TabControlScreen();
		pushScreen(screen);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TabControl app = new TabControl();
		app.enterEventDispatcher();
	}

	private class TabControlScreen extends MainScreen implements FocusChangeListener {

		private LabelField tab1;
		
		private LabelField tab2;

		private LabelField tab3;

		private LabelField spacer1;

		private LabelField spacer2;

		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 VerticalFieldManager tab1Manager;
		private VerticalFieldManager tab2Manager;
		private VerticalFieldManager tab3Manager;
		

		public TabControlScreen() {
			HorizontalFieldManager hManager = new HorizontalFieldManager();
			tab1 = new LabelField("Page 1", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT|FIELD_HCENTER){
				protected void layout(int width, int height) {
					super.layout(width, height);
					setExtent(Display.getWidth()/3, getPreferredHeight());
				}
			};
			tab2 = new LabelField("Page 2", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT){
				protected void layout(int width, int height) {
					super.layout(width, height);
					setExtent(Display.getWidth()/3, getPreferredHeight());
				}
			};
			tab3 = new LabelField("Page 3", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT){
				protected void layout(int width, int height) {
					super.layout(width, height);
					setExtent(Display.getWidth()/3, getPreferredHeight());
				}
			};
			spacer1 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
			spacer2 = new LabelField(" | ", LabelField.NON_FOCUSABLE);

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

			add(hManager);
			add(new SeparatorField());
			
			tab1Manager = new VerticalFieldManager();
			tab2Manager = new VerticalFieldManager();
			tab3Manager = 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);
					}
				}
			}

		}


		public VerticalFieldManager displayTab1() {
			if (tab1Heading == null) {
				tab1Heading = new LabelField("Registration");
				tab1Manager.add(tab1Heading);
			}
			if (tab1Field1 == null) {
				tab1Field1 = new BasicEditField("Username: ", "");
				tab1Manager.add(tab1Field1);
			}
			if (tab1Field2 == null) {
				tab1Field2 = new BasicEditField("Password: ", "");
				tab1Manager.add(tab1Field2);
			}
			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;
		}

	}

}

 Try this.

Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Re: Tab Control Problem

Actualyy I want to do Hide/Show task on click of tabs.
Regular Contributor
heretocode
Posts: 70
Registered: ‎12-19-2011
My Device: Bold 9780

Re: Tab Control Problem

Hi 

 

You can use replace funtion on your manager.

Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Re: Tab Control Problem

Thank you for reply.How to use replace function?
Regular Contributor
heretocode
Posts: 70
Registered: ‎12-19-2011
My Device: Bold 9780

Re: Tab Control Problem

suppose you have a manager as baseManager and two submanger which contains your field and ui.

base1 and base2

baseManager.replace(base1,base2);

it will hide base1 and show base2 manager.

Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930

Re: Tab Control Problem

[ Edited ]

Its working..thanx

Regular Contributor
heretocode
Posts: 70
Registered: ‎12-19-2011
My Device: Bold 9780

Re: Tab Control Problem

Its good to know that it works for you.Now please accept it as solution.