TabField at the bottom of screen not producing click event at all tabs other then 1st tab in blackberry?
===

I am working in a BlackBerry application in which I need to use the tabs at the bottom.

Earlier I had already used the tabs but at the top of the screen. To place the tabs at the bottom of the screen I used the **sublayout()** method. But the side effects of this is I can't use the display(index) method now. Every time when i click on any of the tab, only 1st tab get selected. When i hide the sublayout() method than everything works fine.

This is my code that I am using: 

**TabControl.java**


package com.np.naijapings;


    import com.np.custom.TabField;
    import com.np.naijapings.ui.BuddyListField;
    import com.np.tabscreens.AboutTab;
    import com.np.tabscreens.HomeTab;
    import com.np.tabscreens.SettingTab;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Ui;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.UiEngine;
    import net.rim.device.api.ui.container.MainScreen;
    public class TabControl extends MainScreen{
    	public static int tabHeight = 0;
    	public static TabField mTabField = null;
    	public static Bitmap BACKGROUND_IMAGE = Bitmap
    	.getBitmapResource("Background_Superhero.png");
    	private UiApplication uiApp = UiApplication.getUiApplication();
    	private UiEngine ui = Ui.getUiEngine();
    	private int displayHieght;
    	public TabControl(BuddyListField buddyList) {
    		super(MainScreen.NO_VERTICAL_SCROLL);
    	}
    	public void addFields() {
    		try {
    			mTabField = new TabField(this);
    			add(mTabField);
    			HomeTab home = new HomeTab();
    			mTabField.addTab(Bitmap.getBitmapResource("home_tab.png"), home,
    					Field.FOCUSABLE);
    			SettingTab setting = new SettingTab();
    			mTabField.addTab(Bitmap.getBitmapResource("Setting_tab.png"), setting,
    					Field.FOCUSABLE);
    			AboutTab about = new AboutTab();
    			mTabField.addTab(Bitmap.getBitmapResource("abouttab.png"), about,
    					Field.FOCUSABLE);
    			
    			mTabField.setDefault(Constant.SETTING_TAB_INDEX);
    		} catch (Exception e) {
    			System.out.println(e+"=-====>>TabControl");
    			e.printStackTrace();
    		}
    	}
    	protected boolean keyDown(int keycode, int time) {
    		if (keycode == 1769472) {
    			// escape pressed
    			return true;
    		}
    		return super.keyDown(keycode, time);
    	}
    }


**TabField.java**


    package com.np.custom;
    
    import java.util.Vector;
    
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Ui;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.UiEngine;
    import net.rim.device.api.ui.VirtualKeyboard;
    import net.rim.device.api.ui.component.BitmapField;
    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;
    import net.rim.device.api.ui.decor.Background;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    
    
    
    
    public class TabField extends VerticalFieldManager {
    
    
    	private static Bitmap tabBackGroundImage = Bitmap
    	.getBitmapResource("tab_bar.png");
    	private Background CONTROL_NORMAL_BG = BackgroundFactory
    	.createBitmapBackground(tabBackGroundImage);
    	private Background CONTROL_ACTIVE_BG = BackgroundFactory
    	.createSolidBackground(Color.SILVER);
    
    	public static int indexValue = 0;
    	private static int mCurrentIndex = 0;
    	private int mDefault = 0;
    
    	private Field mCurrentField = null;
    	private Vector mTabFields = new Vector();
    	private MainScreen _mainscreen = null;
    	private HorizontalFieldManager mTabController = new HorizontalFieldManager();
    
    	private UiApplication uiApp = UiApplication.getUiApplication();
    	private UiEngine ui = Ui.getUiEngine();
    	private int tabHieght;
    	private int displayHieght;
    
    
    	public TabField(MainScreen mainscreen) {
    		super(MainScreen.USE_ALL_HEIGHT);
    		_mainscreen = mainscreen;
    		displayHieght = Display.getHeight();
    		
    		add(mTabController);
    		SeparatorField separatorField = new SeparatorField();
    		separatorField.setBackground(CONTROL_ACTIVE_BG);
    		add(separatorField);
    
    	}
    
    	public void setDefault(int index) {
    		mDefault = index;
    		if (mDefault <= mTabFields.size() - 1) {
    			display(mDefault);
    		}
    	}
    
    	public void display(int index) {
    		VirtualKeyboard virtKbd = _mainscreen.getVirtualKeyboard();
    		if(virtKbd != null)
    			virtKbd.setVisibility(VirtualKeyboard.RESTORE);
    
    		try {
    			if (mCurrentField != null) {
    				if (mCurrentField instanceof TabFieldItem) {
    					((TabFieldItem) mCurrentField).onUnSelected();
    				}
    				delete(mCurrentField);
    			}
    			mCurrentField = (Field) mTabFields.elementAt(index);
    			add(mCurrentField);
    			mCurrentField.setFocus();
    
    			if (mCurrentField instanceof TabFieldItem) {
    				((TabFieldItem) mCurrentField).onSelected();
    			}
    
    			setDirty(false);
    			BitmapField mCurrentBG = (BitmapField) mTabController
    			.getField(mCurrentIndex);
    
    			mCurrentBG.setBackground(CONTROL_NORMAL_BG);
    			mCurrentBG.setBitmap(getOnUnFocusImg(mCurrentIndex));
    			BitmapField mBG = (BitmapField) mTabController.getField(index);
    			mBG.setBackground(CONTROL_ACTIVE_BG);
    			mBG.setBitmap(getOnFocusImg(index));
    			mCurrentIndex = index;
    			if(virtKbd != null)
    				virtKbd.setVisibility(VirtualKeyboard.HIDE);
    			if (indexValue == 3) {
    				
    				
    			}
    		} catch (Exception e) {
    			System.out.println("Exception: In TabField--->display() "
    					+ e.toString());
    		}
    	}
    
    	public void addTab(Bitmap aBitmap, final Field aTabField, long style) {
    		BitmapField lButton = null;
    		if (style == Field.FOCUSABLE) {
    			final BitmapField focusbleButton = new BitmapField(aBitmap,
    					Field.FOCUSABLE) {
    				protected boolean navigationClick(int status, int time) {
    					if (aTabField == null) {
    						return false; 
    					}
    					indexValue = getIndex();
    					display(indexValue);
    					return true;
    				}
    
    				protected void paint(Graphics graphics) {
    					if (indexValue == getIndex()) {
    						graphics.setBackgroundColor(Color.SILVER);
    						graphics.clear();
    					}
    					super.paint(graphics);
    				}
    
    				public void setSpace(int hSpace, int vSpace) {
    
    					super.setSpace(hSpace, vSpace);
    				}
    			};
    			focusbleButton.setBackground(CONTROL_NORMAL_BG);
    			setlButtonSpace(focusbleButton);
    			lButton = focusbleButton;
    		} else {
    			lButton = new BitmapField(aBitmap);
    		}
    		/*if (WallpaperMainScreen.tabHeight == 0)
    			WallpaperMainScreen.tabHeight = lButton.getBitmapHeight();*/
    		mTabController.add(lButton);
    		mTabFields.addElement(aTabField);
    
    		if (mDefault == mTabFields.size() - 1 && aTabField != null) {
    			display(mDefault);
    		}
    	}
    
    	//SUBLAYOUT METHOD USED TO BRING THE TABBAR AT THE BOTTOM OF THE SCREEN---------------
    	protected void sublayout(int maxWidth, int maxHeight) {
    		super.sublayout(maxWidth, maxHeight);
    		tabHieght = mTabController.getHeight();
    		int y = displayHieght - tabHieght;
    		setPositionChild(mTabController, 0, y);
    	}
    	
    	
    	private void setlButtonSpace(BitmapField lButton) {
    		int tabWidth = Display.getWidth() / 3;
    		int imagewidth = lButton.getBitmapWidth();
    		int imageheight = lButton.getBitmapHeight();
    		int hPaddingValue = (tabWidth - imagewidth) / 2;
    		int vPaddingValue = (tabWidth - imageheight) / 7;
    		lButton.setSpace(hPaddingValue + 1, vPaddingValue);
    	}
    
    	private Bitmap getOnFocusImg(int index) {
    		Bitmap image = null;
    		switch (index) {
    		case 0:
    			image = Bitmap.getBitmapResource("home_tab.png");
    			break;
    		case 1:
    			image = Bitmap.getBitmapResource("Setting_tab.png");
    			break;
    		case 2:
    			image = Bitmap.getBitmapResource("about_tab.png");
    			break;
    		/*case 3:
    			image = Bitmap.getBitmapResource("exit_tab.png");
    			break;
    */
    		}
    		return image;
    	}
    
    	private Bitmap getOnUnFocusImg(int currentIndex) {
    		Bitmap image = null;
    		switch (currentIndex) {
    		case 0:
    			image = Bitmap.getBitmapResource("home_tab.png");
    			break;
    		case 1:
    			image = Bitmap.getBitmapResource("Setting_tab.png");
    			break;
    		case 2:
    			image = Bitmap.getBitmapResource("about_tab.png");
    			break;
    		/*case 3:
    			image = Bitmap.getBitmapResource("exit_tab.png");
    			break;*/
    		}
    		return image;
    
    	}
    
    	
    	protected boolean keyChar(char ch, int status, int time) {
    		if (mCurrentField != null && mCurrentField instanceof TabFieldItem) {
    			return ((TabFieldItem) mCurrentField).keyChar(ch, status, time);
    		} else {
    			return super.keyChar(ch, status, time);
    		}
    	}
    }

**TabFieldItem.java**


    package com.np.custom;
    
    public interface TabFieldItem {
    	/**
    	 * Method invoked when the tabField is about to be displayed
    	 */
    	public void onSelected();
    
    	/**
    	 * Method invoked when the tabField is about to be removed from the display
    	 */
    	public void onUnSelected();
    
    	public boolean keyChar(char ch, int status, int time);
    
    }


I have used the sublyout method in TabField.java class.
and the result is as shown in the image.

![enter image description here][1]


  [1]: http://i.stack.imgur.com/MUco8.png