2014-02-28 100 views
0

我一直在研究一个小应用程序,它的这一部分已经让我难堪了。我有一个listField(如屏幕截图中的按钮上方所示),某些按钮以及此页面上的一些静态editFields,并且我在滚动时遇到问题。自定义列表字段

我希望listField被限制为显示5行(它在屏幕截图中显示2),并且如果listField中有5个以上的项目,可以滚动浏览它们(不滚动整个页面,只是列表视图)。

我也有另外一个问题与editFields,如果他们变得过大,由于大量的文字,他们将消失在屏幕上,因为我的屏幕不会在未向super(Manager.NO_VERTICAL_SCROLL);一个呼叫时,显然需要对listField运行的工作。

解决此问题的唯一方法是实现完整的自定义类listField?还是有更简单的选择?

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

感谢,奎因

编辑:

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

} 

}

这里是我添加的示例页面,以及它的另一个截图ooks运行时:http://imgur.com/xtPNr7p

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

回答

0

对不起,只是一个局部的答案,因为它已远远超过我的睡觉时间....

ListField不需要NO_VERTICAL_SCROLL,但一些较新的UI控件似乎确实。我避免这些......

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

为了限制大小,你应该重写VFM的子布局,我最近没有这样做,但我认为这很简单,只需调用super.sublayout,传入的宽度和高度受限。

要理解这是什么做的,回顾这两个知识库文章:

Custom layout manager

Extend Manager

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

更新

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

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

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

因此,虽然我很乐意尝试帮助的,如果你决定你想尝试哪一个以上的选项之一,我先提醒你考出这样的设计更加以确保它的工作原理。

+0

全部修好!我用你在#1说着,改变了清单上是一个经常ListField,这一切都工作正常。关于UI不是非触摸屏的工作,有什么我工作是在公司内部使用,都已经触摸屏手机的客户,使非触摸屏不是问题。我将在以后的版本中加入了更多的功能,但是这是目前正在所需的全部。再一次,非常感谢你的帮助! – Br0k3nL1m1ts