在黑莓主屏幕中打开新主屏幕
我正在制作一个应用程序,其中每个选项卡上都有几个选项卡,单击一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于您的 TabControl 类
对于您的新闻类
For your TabControl Class
For your News class
是的,创建一个单独的主屏幕或屏幕对象,然后从您的父屏幕中,您可以执行以下代码以使用以下代码打开新屏幕:
谢谢
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:
Thanks
您不需要在您描述的场景中创建 2 个主屏幕。
只需创建一个 VerticalFieldManager,将其添加到主屏幕,然后向其中添加内容即可。
这里有一个代码示例可以帮助您,将其应用到主屏幕构造函数中。
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.