Search code examples
blackberrylistfield

Scroll only single listfield in multiple listfields blackberry


I'm new to blackberry and I've a question, I've 3 listfields in a row like

[--------One--------][--Two--][--Three--]

but when I scroll single one, every one scrolls!, how do I restrict scroll of others when focused one is scrolling?

EDIT

// 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


Solution

  • The key is that you need to disable vertical scrolling for the Screen that contains all these managers and fields.

    Then, you can create one horizontal field manager. And then, three vertical field managers. Put each list in its own vertical field manager, and then all three vertical field managers go into the horizontal field manager.

    Here's a simple prototype that I tested:

    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
       }   
    }
    

    Results

    enter image description here

    As you can see, I was able to get each list scrolling vertically, independently.