BlackBerry - 将项目添加到 ListField

发布于 2024-07-11 23:15:44 字数 237 浏览 6 评论 0原文

有人可以给我一个简单的例子,说明如何向 ListField 添加三行,以便列表显示这样的内容吗?

项目 1

项目 2

项目 3

我只想显示一个列表,用户可以在其中选择其中一个项目,并且程序将根据所选项目执行某些操作。

我在互联网上进行了搜索,但似乎不可能找到一个关于如何执行此操作的简单示例(我发现的大多数示例都不完整),并且黑莓文档非常糟糕。

谢谢!

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?

Item 1

Item 2

Item 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.

Thanks!

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

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

发布评论

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

评论(5

素手挽清风 2024-07-18 23:15:44

您可能想了解如何使用 ObjectListField。 处理选择操作是通过包含的 Screen 对象完成的,我在下面使用 MenuItem 完成了此操作,我不太确定如何设置默认选择侦听器,您可能必须检测按键和拨轮事件。

一些示例代码:(未经测试!)

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

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.

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);
若水微香 2024-07-18 23:15:44

您可以像这样重写 navigationClick 方法:

ObjectListField list = new ObjectListField()
{
    protected boolean navigationClick(int status, int time)
    {
        // Your implementation here.
    }
};

You can override the navigationClick method like this:

ObjectListField list = new ObjectListField()
{
    protected boolean navigationClick(int status, int time)
    {
        // Your implementation here.
    }
};
━╋う一瞬間旳綻放 2024-07-18 23:15:44
final class SimpleListScreen extends MainScreen
{
    public SimpleListScreen()
    {
        super(Manager.NO_VERTICAL_SCROLL);

        setTitle("Simple List Demo");

        add(new LabelField("My list", LabelField.FIELD_HCENTER));
        add(new SeparatorField());

        Manager mainManager = getMainManager();

        SimpleList listField = new SimpleList(mainManager);

        listField.add("Item 1");
        listField.add("Item 2");
        listField.add("Item 3");
        }
    }

    //add listener so that when an item is chosen,it will do something
final class SimpleListScreen extends MainScreen
{
    public SimpleListScreen()
    {
        super(Manager.NO_VERTICAL_SCROLL);

        setTitle("Simple List Demo");

        add(new LabelField("My list", LabelField.FIELD_HCENTER));
        add(new SeparatorField());

        Manager mainManager = getMainManager();

        SimpleList listField = new SimpleList(mainManager);

        listField.add("Item 1");
        listField.add("Item 2");
        listField.add("Item 3");
        }
    }

    //add listener so that when an item is chosen,it will do something
你是年少的欢喜 2024-07-18 23:15:44
private ListField fList = new ListField(){
        protected boolean navigationClick(int status, int time) {
            System.out.println("omt Click");
            return true;
        };
    };
private ListField fList = new ListField(){
        protected boolean navigationClick(int status, int time) {
            System.out.println("omt Click");
            return true;
        };
    };
温柔嚣张 2024-07-18 23:15:44

您可以通过覆盖然后检测每个列表项的点击

protected boolean navigationClick(int status,int time)

,您只需要弄清楚如何响应点击即可。 我这样做的方法是使用为每个列表项设置的匿名类。

You can detect the click on each list item by overriding

protected boolean navigationClick(int status,int time)

Then you just need to work out what to do in response to the click. The way I did this was by using an anonymous class, set for each list item.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文