自定义列表字段的各个部分

时间:2014-02-28 00:57:22

标签: java blackberry java-me listfield

我一直在研究一个小应用程序,它的这一部分让我难过。我在此页面上有一个listField(如屏幕截图中的按钮所示),一些按钮和一些静态editFields,我在滚动时遇到问题。

我希望listField仅限于显示5行(在屏幕截图中显示2),如果listField中有超过5个项目,则可以滚动它们(不滚动)整个页面,只是listview)。

我还有另一个关于editFields的问题,如果它们由于大量文本而变得太大,它们将从屏幕上消失,因为如果没有调用显然需要的super(Manager.NO_VERTICAL_SCROLL);我的屏幕将无法运行工作listField

解决此问题的唯一方法是实现listField的完整自定义类吗?或者是否有更简单的替代方案?

(imgur截图,因为我没有足够的代表发布图片) http://imgur.com/RcfspQP

谢谢,Quinn

修改

public class TestScreen extends MainScreen{
public TestScreen(){
    //Without this call to super (which turns off vertical scrolling) the program throws an IllegalStateException and won't open the screen
    super(Manager.NO_VERTICAL_SCROLL);

    //Create some managers to organize the different Fields
    VerticalFieldManager verticalAllManager = new VerticalFieldManager();
    VerticalFieldManager verticalInfoManager = new VerticalFieldManager();
    //Going to use this to limit the number of rows the list will display
    VerticalFieldManager verticalListManager = new VerticalFieldManager()
    {
        protected void sublayout(int width, int height) {
            //Just test numbers
            super.sublayout(width, 100);
        }
    };
    HorizontalFieldManager horizontalButtonManager = new HorizontalFieldManager();

    //Add a title bar
    add(new LabelField("Choose the call you want to view", LabelField.FIELD_HCENTER));
    add(new SeparatorField());

    //Creates the SimpleList ListField
    Manager mainManager = getMainManager();
    final SimpleList listField = new SimpleList(mainManager);

    //Add items to the listField
    listField.add("Time: 12:30 | Date: 3:10:2014");
    listField.add("Time: 03:13 | Date: 1:25:2013");

    //Creates a button to use for selecting the desired call
    final ButtonField selectCall = new ButtonField("Select Call", ButtonField.CONSUME_CLICK);

    //Creates fields for all the required information (blank to start)
    final BasicEditField timeField, dateField, numberField, nameField;
    timeField = new BasicEditField("Call Time: ", "");
    dateField = new BasicEditField("Call Date: ", "");
    numberField = new BasicEditField("Call Number: ", "");
    nameField = new BasicEditField("Caller Name: ", "");

    //Creates a button that can be used to save changes
    final ButtonField saveChanges = new ButtonField("Save Changes", ButtonField.CONSUME_CLICK);
    final ButtonField deleteRow = new ButtonField("Delete Call", ButtonField.CONSUME_CLICK);

    //Adds all the info fields into a vertical manager to organize them
    verticalInfoManager.add(timeField);
    verticalInfoManager.add(dateField);
    verticalInfoManager.add(numberField);
    verticalInfoManager.add(nameField);

    //Adds the 3 buttons to a horizontal manager to lay them out in a row
    horizontalButtonManager.add(selectCall);
    horizontalButtonManager.add(saveChanges);
    horizontalButtonManager.add(deleteRow);

    //Add the horizontal button manager to the vertical page manager
    verticalAllManager.add(horizontalButtonManager);

    //Add the vertical info manager to the vertical page manager
    verticalAllManager.add(verticalInfoManager);

    //Add all the managers, under the page manager, to the page
    add(verticalAllManager);

}

}

以下是我添加的示例页面,以及运行时的外观截图:http://imgur.com/xtPNr7p

现在最大的问题是使用NO_VERTICAL_SCROLL调用super()会关闭整个页面的滚动。没有那个调用,信息字段会滚动,我只是(我想是这样)需要将verticalListManager和horizo​​ntalButtonManager添加到横幅以防止它们滚动。

1 个答案:

答案 0 :(得分:0)

对不起,只有部分答案,因为它已经过了我的睡觉时间....

ListField不需要NO_VERTICAL_SCROLL,尽管似乎有一些较新的UI控件。我避免这些......

将ListField限制为仅显示5个“行”的方法是将其放在滚动的VerticalFieldManager中,然后将VFM的大小限制为显示5行所需的大小。

要限制大小,你应该覆盖VFM的sublayout,我最近没有这样做,但我认为这就像调用传递的宽度和高度限制的super.sublayout一样简单。

要了解这是做什么的,请查看以下两篇知识库文章:

Custom layout manager

Extend Manager

如果这不起作用,请粘贴我们可以“修复”的示例代码以显示此工作。基本上创建一个简单的独立MainScreen,其中包含ListField和按钮以及EditFields,用于演示您已识别的问题,将其粘贴到另一个屏幕截图中,我相信这里有人会为您创建更正版本的代码。

<强>更新

啊,我看到你使用了一个较新的UI类,SimpleList,在我看来,其中一些没有正确编码,因为,正如你所知,它们确实需要NO_VERTICAL_SCROLL。我怀疑如果你真的将它们添加到具有固定高度的非滚动VFM,那么处理可能会按照你想要的方式工作。但对我来说,这里没有选择,我会编写一个正常的ListField,新的UI控件似乎也有其他限制,对我来说,它们提供的简化只是隐藏了我喜欢使用的功能。

无论如何,我认为你有三个选择: 1)将您的编辑字段添加到状态区域(setStatus(...)) - 然后它们将粘在屏幕的底部。将标题标签添加到标题区域(setTitle(..))。然后让你的电话在中间滚动。 2)尝试将SimpleList放入非滚动但高度受限的VFM中。 3)将SimpleList更改为普通的ListField。

那就是说,你选择的Ui在我看来对于非触摸屏手机来说是个问题。如何在仅触控板设备上的用户选择呼叫?我会看一下使用菜单为所选行提供“按钮”。要编辑行,请使用带有详细信息的弹出屏幕。

因此,虽然我很乐意尝试帮助您完成上述其中一个选项,但如果您决定尝试哪一个,我会首先提醒您更多地测试这个设计以确保其有效。