问题描述
有人可以给我如何三行添加到ListField一个简单的例子,这样的列表显示了这样的事?
Can someone please give me a simple example on how to add three rows to a ListField so that the list shows something like this?
项目1
项目2
项目3
我只想显示,其中用户可以选择项目之一,该方案将取决于所选择的项目做一些事情的列表。
I just want to show a list in which the user can select one of the items and the program would do something depending on the item selected.
我搜索了所有在互联网上,但它似乎无法找到如何做一个简单的例子(我发现大多数的例子是不完整的)和黑莓的文档是可怕的。
I've search all over the internet but it seems impossible to find a simple example on how to do this (most examples I found are incomplete) and the blackberry documentation is terrible.
谢谢!
推荐答案
您可能想看看使用ObjectListField。处理选择动作throught包含Screen对象做的,我做这下面使用菜单项,我真的不知道如何设置默认选择监听器,您可能需要检测键和拨轮事件。
You probably want to look at using an ObjectListField. Handling the select action is done throught the containing Screen object, I've done this below using a MenuItem, I'm not really sure how to set a default select listener, you may have to detect key and trackwheel events.
一些示例code为您提供:(!未测试)
Some example code for you: (not tested!)
MainScreen screen = new MainScreen();
screen.setTitle("my test");
final ObjectListField list = new ObjectLIstField();
String[] items = new String[] { "Item 1", "Item 2", "Item 3" };
list.set(items);
screen.addMenuItem(new MenuItem("Select", 100, 1) {
public void run() {
int selectedIndex = list.getSelectedIndex();
String item = (String)list.get(selectedIndex);
// Do someting with item
});
screen.add(list);
这篇关于黑莓 - 添加项目到ListField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!