blackberry - 屏幕底部的 TabField 不会在黑莓中除第一个选项卡之外的所有选项卡上产生单击事件?

标签 blackberry tabbar

我正在使用 BlackBerry 应用程序,需要使用底部的选项卡。

之前我已经使用过这些选项卡,但位于屏幕顶部。为了将选项卡放置在屏幕底部,我使用了 sublayout() 方法。但这样做的副作用是我现在无法使用 display(index) 方法。每次我单击任何选项卡时,只会选择第一个选项卡。当我隐藏 sublayout() 方法时,一切正常。

这是我正在使用的代码:

TabControl.java

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

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);

}

我在 TabField.java 类中使用了 sublyout 方法。 结果如图所示。

enter image description here

最佳答案

在“add(mTabController)”上方添加一个管理器,并将该管理器的固定高度覆盖子布局并在子布局内设置setextent,高度必须是displayheight-mtabcontroller高度。并删除 tabfield 类中覆盖的子布局。

关于blackberry - 屏幕底部的 TabField 不会在黑莓中除第一个选项卡之外的所有选项卡上产生单击事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11699571/

相关文章:

java - 我们可以将文本转换为语音,反之亦然吗?

listview - 如何在 Flutter 中使用 ListView 处理 TabBar?

ios - 当通过 segue 返回时,选项卡栏会从 viewController 中消失 - swift

ios - 是否可以从一个标签栏 Controller 导航到另一个标签栏 Controller ?

android - 如何在android中的listview下方添加footbar按钮

java - 如何使用 OutputStream 将新行插入到黑莓的文本文件中?

blackberry - 外部播放BlackBerry上录制的音频

java - 如何在黑莓java应用程序中生成pdf文件

reactjs - 将导入的图标添加到 TabBarIOS.Item