2014-02-28 169 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