在黑莓主屏幕中打开新主屏幕

发布于 2024-11-08 03:06:32 字数 5213 浏览 0 评论 0原文

我正在制作一个应用程序,其中每个选项卡上都有几个选项卡,单击一个 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());
    }
}
}

现在我想在选项卡下方打开此新闻屏幕 请帮忙

I'm making an application in which there are few tabs on each tab click a url is called and an online xml is parsed. The data from this xml is displayed. The problem is that when the data is dispalyed the tabs disappear and only appear when i press the back button of the simulator. Whereas the data should appear below the tabs.

Please help

My UI

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

}
}

My News Main Screen

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

Now i want to open this news screen below the tabs
Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

写给空气的情书 2024-11-15 03:06:32

对于您的 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());
        }
    }
}

For your TabControl Class

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
        }
    }
 }

For your News class

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());
        }
    }
}
疾风者 2024-11-15 03:06:32

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

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

谢谢

Yes, create a seprate mainscreen or screen objects and from your parent screen you can execute the below code to open new screen using the below code:

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

Thanks

提笔书几行 2024-11-15 03:06:32

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

这里有一个代码示例可以帮助您,将其应用到主屏幕构造函数中。

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

You don't need to create 2 mainscreens in the scenario which you described.
Just create a VerticalFieldManager, add it to the mainscreen, then add content to it.

Here's a sample of code that can help you, apply it in your mainscreen constructor.

VerticalFieldManager VFM_Content = new VerticalFieldManager();
add(VFM_Content);
VFM_Content.add(/*put content here embedded in any field type you prefer*/);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文