在多个listfields blackberry中仅滚动单个列表字段

时间:2013-07-29 07:59:38

标签: blackberry listfield

我是黑莓新手,我有一个问题,我连续3个列表区域

[-------- --------一个] [ - 双 - ] [ - 三 - ]

但是当我滚动单曲时,每一个都滚动!当聚焦滚动时,如何限制其他人的滚动?

修改

// ListFields
HorizontalFieldManager hfmMain = new HorizontalFieldManager();

HorizontalFieldManager hfmFist = new HorizontalFieldManager(FIELD_LEFT);
hfmFist.add(myListView);

HorizontalFieldManager hfmSecond = new HorizontalFieldManager();
hfmSecond.add(hizabListView);

HorizontalFieldManager hfmThird = new HorizontalFieldManager();
hfmThird.add(paraListView);

hfmMain.add(hfmFist);
hfmMain.add(hfmSecond);
hfmMain.add(hfmThird);

add(hfmMain);

enter image description here

2 个答案:

答案 0 :(得分:1)

您在一个屏幕管理器中有多个列表字段,当您向下滚动并选择此管理器时,滚动事件将被发送到所有这些字段。所有这些都是同时滚动。

我会将每个listfield分成自己的经理。

答案 1 :(得分:1)

关键是您需要为包含所有这些管理器和字段的Screen禁用垂直滚动。

然后,您可以创建一个水平字段管理器。然后,三个垂直的现场经理。将每个列表放在自己的垂直字段管理器中,然后所有三个垂直字段管理器都进入水平字段管理器。

这是我测试过的简单原型:

public class ListFocusScreen extends MainScreen implements ListFieldCallback {

   private ObjectListField list1;
   private ListField list2;
   private ListField list3;
   private Bitmap icon2;   // for list 2 cell background
   private Bitmap icon3;   // for list 3 cell background

   public ListFocusScreen() {
      // Do NOT allow vertical scrolling at the Screen level!!
      super(MainScreen.NO_VERTICAL_SCROLL | MainScreen.NO_VERTICAL_SCROLLBAR);

      // A container for the "row" of three side-by-side lists
      HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH);

      // Do create a vertical field manager for each list, that scrolls
      VerticalFieldManager vfm1 = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) {
         protected void sublayout(int maxWidth, int maxHeight) {
            super.sublayout(2 * Display.getWidth() / 3, maxHeight);   // 2/3 width
         }         
      };
      VerticalFieldManager vfm2 = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) {
         protected void sublayout(int maxWidth, int maxHeight) {
            super.sublayout(Display.getWidth() / 6, maxHeight);       // 1/6 width
         }         
      };
      VerticalFieldManager vfm3 = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) {
         protected void sublayout(int maxWidth, int maxHeight) {
            super.sublayout(Display.getWidth() / 6, maxHeight);       // 1/6 width
         }         
      };

      Object[] listData1 = new Object[24];
      for (int i = 0; i < listData1.length; i++) {
         // generate fake data for list1
         listData1[i] = String.valueOf(i) + ". Click to Download";
      }
      list1 = new ObjectListField();
      list1.set(listData1);

      list2 = new ListField();
      list2.setCallback(this);
      icon2 = Bitmap.getBitmapResource("octagon.png");
      list2.setSize(15);

      list3 = new ListField();
      list3.setCallback(this);
      icon3 = Bitmap.getBitmapResource("frame.png");
      list3.setSize(15);

      vfm1.add(list1);
      vfm2.add(list2);
      vfm3.add(list3);
      hfm.add(vfm1);
      hfm.add(vfm2);
      hfm.add(vfm3);
      add(hfm);
   }

   public void drawListRow(ListField listField, Graphics graphics, int index,
         int y, int width) {
      // this same method will be used for custom drawing of both lists 2 and 3
      final int PAD = 4;
      String text = (String)get(listField, index);
      if (listField == list2) {
         graphics.drawBitmap(0, y, width, width, icon2, 0, 0);
         graphics.drawText(text, PAD, y + PAD);
      } else if (listField == list3) {
         graphics.drawBitmap(0, y, width, width, icon3, 0, 0);
         graphics.drawText(text, PAD, y + PAD);
      }      
   }

   public Object get(ListField listField, int index) {
      // TODO: normally, get this value from a vector of actual 
      //  data for each list
      return String.valueOf(index);
   }

   public int getPreferredWidth(ListField listField) {
      return Display.getWidth() / 6;
   }

   public int indexOfList(ListField listField, String prefix, int start) {
      return -1;  // no search support
   }   
}

结果

enter image description here

如您所见,我能够让每个列表垂直滚动,独立