在黑莓的主屏幕内打开一个新的主屏幕

时间:2011-05-18 05:47:19

标签: blackberry uiapplication

我正在创建一个应用程序,其中每个选项卡上的选项卡都很少,单击一个URL并调用在线xml。显示此xml中的数据。问题是,当数据被显示时,标签消失,只有当我按下模拟器的后退按钮时才会出现。而数据应显示在标签下方。

请帮忙

我的用户界面

public class TabControl extends UiApplication {

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

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

private class TabControlScreen extends MainScreen implements FocusChangeListener {

    private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");

    private LabelField tab1;
    private LabelField tab2;
    private LabelField tab3;


    private VerticalFieldManager tabArea;
    private VerticalFieldManager tab1Manager;
    private VerticalFieldManager tab2Manager;
    private VerticalFieldManager tab3Manager;

    public TabControlScreen() {

        LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
        this.setTitle(appTitle);

        HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {

            // Override the paint method to draw the background image.
            public void paint(Graphics graphics) {
                // Draw the background image and then call paint.
                graphics.drawBitmap(0, 0, 700, 100, backgroundBitmap, 0, 0);
                super.paint(graphics);
            }
        };
        tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
            protected boolean navigationClick(int status,int time){
                tabArea = displayTab1();
                return true;
            }
        };
        LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
        tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
            protected boolean navigationClick(int status,int time){
                tabArea = displayTab2();
                return true;
            }
        };
        LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
        tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
            protected boolean navigationClick(int status,int time){
                tabArea = displayTab3();
                return true;
            }
        };


        tab1.setFocusListener(this);
        tab2.setFocusListener(this);
        tab3.setFocusListener(this);

        hManager.add(tab1);
        hManager.add(separator);
        hManager.add(tab2);
        hManager.add(separator1);
        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) {
                    delete(tabArea);
                    tabArea = displayTab1();
                    add(tabArea);
                } else if (field == tab2) {
                    delete(tabArea);
                    tabArea = displayTab2();
                    add(tabArea);
                } else if (field == tab3) {
                    delete(tabArea);
                    tabArea = displayTab3();
                    add(tabArea);
                }
            }
        }
    }

    public VerticalFieldManager displayTab1() {

        UiApplication.getUiApplication().pushScreen(new News());
        return tab1Manager;
    }

    public VerticalFieldManager displayTab2() {

        UiApplication.getUiApplication().pushScreen(new Power());
        return tab2Manager;
    }

    public VerticalFieldManager displayTab3() {

        UiApplication.getUiApplication().pushScreen(new Energy());
        return tab3Manager;
    }

}
}

我的新闻主屏幕

public class News extends MainScreen {
public News() {

    String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";

    String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
    for (int i = 0; i < urlData.length; i++) {
        final String title = urlData[0][i];
        final String id = urlData[1][i];
        //add(new LinkLabel(title, i));
        add(new RichTextField(title){
            protected boolean navigationClick(int status,int time){

                String cId = id;
                String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
                String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
                for(int j=0;j<bodyData.length;j++){
                    String body = bodyData[0][j];
                    add(new RichTextField(body));
                }
                return true;
            }
        });
        add(new SeparatorField());
    }
}
}

现在我想在标签下方打开此新闻屏幕 请帮忙

3 个答案:

答案 0 :(得分:1)

对于TabControl类

public class TabControl extends UiApplication {

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

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

    private class TabControlScreen extends MainScreen {

        private Bitmap backgroundBitmap = Bitmap.getBitmapResource("rednavnar.png");

        private LabelField tab1;
        private LabelField tab2;
        private LabelField tab3;

        private VerticalFieldManager tabArea;

        public TabControlScreen() {

            LabelField appTitle = new LabelField("Energy", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);
            this.setTitle(appTitle);

            HorizontalFieldManager hManager = new HorizontalFieldManager( Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH | Manager.TOPMOST) {

                // Override the paint method to draw the background image.
                public void paint(Graphics graphics) {
                    // Draw the background image and then call paint.
                    graphics.drawBitmap(0, 0, 700, 100, backgroundBitmap, 0, 0);
                    super.paint(graphics);
                }
            };
            tab1 = new LabelField("Top News", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
                protected boolean navigationClick(int status,int time){
                    delete(tabArea);
                    tabArea = displayTab1();
                    add(tabArea);
                    return true;
                }
            };
            LabelField separator = new LabelField("|", LabelField.NON_FOCUSABLE);
            tab2 = new LabelField("Power", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
                protected boolean navigationClick(int status,int time){
                    delete(tabArea);
                    tabArea = displayTab2();
                    add(tabArea);
                    return true;
                }
            };
            LabelField separator1 = new LabelField("|", LabelField.NON_FOCUSABLE);
            tab3 = new LabelField("Renewable Energy", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_FOCUS){
                protected boolean navigationClick(int status,int time){
                    delete(tabArea);
                    tabArea = displayTab3();
                    add(tabArea);
                    return true;
                }
            };

            hManager.add(tab1);
            hManager.add(separator);
            hManager.add(tab2);
            hManager.add(separator1);
            hManager.add(tab3);

            add(hManager);
            add(new SeparatorField());

            // USELESS CODE HAS BEEN REMOVED    

            tabArea = displayTab1();
            add(tabArea);

        }

        public VerticalFieldManager displayTab1() {
            return new News(); // RETURN THE MANAGER DIRECTLY
        }

        public VerticalFieldManager displayTab2() {
            return new Power(); // RETURN THE MANAGER DIRECTLY
        }

        public VerticalFieldManager displayTab3() {
            return new Energy(); // RETURN THE MANAGER DIRECTLY
        }
    }
 }

为您的新闻类

public class News extends VerticalFieldManager { // CHANGING THE EXTENSION SUPER CLASS 
    public News() {
        super(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR);

        String xmlUrl = "http://182.71.5.53:9090/solr/core4/select/?q=*";

        String[][] urlData = XmlFunctions.getURLFromXml(xmlUrl);
        for (int i = 0; i < urlData.length; i++) {
            final String title = urlData[0][i];
            final String id = urlData[1][i];
            //add(new LinkLabel(title, i));
            add(new RichTextField(title){
                protected boolean navigationClick(int status,int time){

                    String cId = id;
                    String bodyUrl = "http://192.168.1.44:9090/solr/core0/select/?q="+cId+";
                    String[][] bodyData = XmlFunctions.getBodyFromXml(bodyUrl);
                    for(int j=0;j<bodyData.length;j++){
                        String body = bodyData[0][j];
                        add(new RichTextField(body));
                    }
                    return true;
                }
            });
            add(new SeparatorField());
        }
    }
}

答案 1 :(得分:0)

是的,创建一个单独的主屏幕或屏幕对象,您可以使用以下代码执行以下代码打开新屏幕:

UIApplication.getUiApplication().pushScreen(your custom screen object);

由于

答案 2 :(得分:0)

您不需要在所描述的场景中创建2个主屏幕。
只需创建一个VerticalFieldManager,将其添加到主屏幕,然后添加内容即可。

以下是可以帮助您的代码示例,将其应用于主屏幕构造函数。

VerticalFieldManager VFM_Content = new VerticalFieldManager();
add(VFM_Content);
VFM_Content.add(/*put content here embedded in any field type you prefer*/);