在黑莓标签 [英] Tabs in Blackberry
问题描述
我开发黑莓应用程序,我是新手,所以不知道如何执行。
I am developing application in BlackBerry and i am a newbie, so no idea how to implement.
在我的应用程序必须实现标签。为此,我使用pillButtonSet。在我的应用我有五个选项卡和每个标签都有复杂的视图。我想创建不同的标签不同的Java类。
In my application i have to implement tabs. For this i used pillButtonSet. In my application i have five tabs and each tab has complex view. I want to create different java class for different tabs.
如的Android,我们有 TabActivity
,我们选项卡之间轻松导航。直到现在我还没有设计对每个选项卡中的视图。我使用Google,但没有成功。
As in Android we have TabActivity
and we easily navigate between tabs. Still i have not designed the view for each tabs. I am googling but no success.
我担心;我需要写完整的code在一个屏幕上? ....如果不是我在哪里要创建标签和如何定位?
I am worried; do i need to write whole code on one screen? .... If not where do i have to create tabs and how to navigate?
推荐答案
在看看<一个href=\"http://supportforums.blackberry.com/t5/Java-Development/Create-tabbed-view-screens/ta-p/444969\"相对=nofollow>从RIM 这款黑莓的例子。这是一个有点老了,但如果你仍然有支持OS 5.0,这是一个很有用的技术(见答案的底部,如果你不支持OS 5.0)。
Take a look at this BlackBerry example from RIM. It's a bit old, but if you still have to support OS 5.0, it's a useful technique (see bottom of answer if you don't support OS 5.0).
这说明:
的基本方法是使用一组管理来控制的集
当已经选择了一个选项卡上的屏幕显示领域。标签
被实现为可聚焦LabelFields,具有FocusChangeListener
做经理开关时,焦点变化。字段和经理
初始化一次,并保持在内存中保留状态变化
标签之间。
The basic approach is to use a set of Managers to control the sets of Fields that appear on the Screen when a tab has been selected. Tabs are implemented as focusable LabelFields, with a FocusChangeListener doing the Manager switch when focus changes. Fields and Managers are initialized once and maintained in memory to retain state changes between tabs.
该页面有样品code下载,但以防止任何可能的环节腐,这里的样品中最重要的部分:
The page has sample code to download, but to protect against any possible link rot, here's the most important part of the sample:
package com.rim.samples.tabcontrol;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.LabelField;
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;
public class TabControl extends UiApplication {
public TabControl() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
/**
* @param args
*/
public static void main(String[] args) {
TabControl app = new TabControl();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen implements FocusChangeListener {
private LabelField tab1;
private LabelField tab2;
private LabelField tab3;
private LabelField spacer1;
private LabelField spacer2;
private VerticalFieldManager tabArea;
private LabelField tab1Heading;
private BasicEditField tab1Field1;
private BasicEditField tab1Field2;
private LabelField tab2Heading;
private BasicEditField tab2Field1;
private BasicEditField tab2Field2;
private LabelField tab3Heading;
private BasicEditField tab3Field1;
private BasicEditField tab3Field2;
private VerticalFieldManager tab1Manager;
private VerticalFieldManager tab2Manager;
private VerticalFieldManager tab3Manager;
public TabControlScreen() {
HorizontalFieldManager hManager = new HorizontalFieldManager();
tab1 = new LabelField("Page 1", LabelField.FOCUSABLE);
tab2 = new LabelField("Page 2", LabelField.FOCUSABLE);
tab3 = new LabelField("Page 3", LabelField.FOCUSABLE);
spacer1 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
spacer2 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
tab1.setFocusListener(this);
tab2.setFocusListener(this);
tab3.setFocusListener(this);
hManager.add(tab1);
hManager.add(spacer1);
hManager.add(tab2);
hManager.add(spacer2);
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) {
System.out.println("Switch to Tab 1");
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
} else if (field == tab2) {
System.out.println("Switch to Tab 2");
System.out.println("Switch to Tab 1");
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
} else if (field == tab3) {
System.out.println("Switch to Tab 3");
System.out.println("Switch to Tab 1");
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
}
}
}
}
public VerticalFieldManager displayTab1() {
if (tab1Heading == null) {
tab1Heading = new LabelField("Registration");
tab1Manager.add(tab1Heading);
}
if (tab1Field1 == null) {
tab1Field1 = new BasicEditField("Username: ", "");
tab1Manager.add(tab1Field1);
}
if (tab1Field2 == null) {
tab1Field2 = new BasicEditField("Password: ", "");
tab1Manager.add(tab1Field2);
}
return tab1Manager;
}
public VerticalFieldManager displayTab2() {
if (tab2Heading == null) {
tab2Heading = new LabelField("Password Recovery");
tab2Manager.add(tab2Heading);
}
if (tab2Field1 == null) {
tab2Field1 = new BasicEditField("Security Question: ", "Mother's Maiden Name?");
tab2Manager.add(tab2Field1);
}
if (tab2Field2 == null) {
tab2Field2 = new BasicEditField("Password: ", "");
tab2Manager.add(tab2Field2);
}
return tab2Manager;
}
public VerticalFieldManager displayTab3() {
if (tab3Heading == null) {
tab3Heading = new LabelField("Interests");
tab3Manager.add(tab3Heading);
}
if (tab3Field1 == null) {
tab3Field1 = new BasicEditField("Hobbies: ", "");
tab3Manager.add(tab3Field1);
}
if (tab3Field2 == null) {
tab3Field2 = new BasicEditField("Memberships: ", "");
tab3Manager.add(tab3Field2);
}
return tab3Manager;
}
}
}
您说:
我要为不同的分页创建不同的Java类。
I want to create different java class for different tabs.
在您的code,您可以编辑命名方法 displayTab1()
, displayTab2()
,等返回不同的类为每个标签。下面的例子正好,每个班将延长
的 VerticalFieldManager
类。不过,如果你期望的实现不能很好地设置了 VerticalFieldManager
,你当然可以改变这些方法的返回值仅仅是管理
基类来代替。
In your code, you can edit the methods named displayTab1()
, displayTab2()
, etc. to return a different class for each tab. Following the example exactly, each class would extend
the VerticalFieldManager
class. However, if your desired implementation isn't well setup for a VerticalFieldManager
, you could certainly change the return value of those methods to just be the Manager
base class, instead.
请记住,如果你做的修改 tabArea
成员变量:
Just remember to change the tabArea
member variable if you do that:
private Manager tabArea;
注意:如果您只需要支持OS 6.0及以上版本,你也可以看看<一个href=\"http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/ui/component/pane/HorizontalTabController.html\"相对=nofollow>这个新的API
Note: if you only have to support OS 6.0 and above, you can also look into this newer API
这篇关于在黑莓标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!