2012-04-04 69 views
0

我正在使用以下代碼的列表。我已經使用RichTextField作爲列表項。黑莓RichTextField重點概率

public class ListScreen extends MainScreen { 

    private UiApplication application; 
    private VerticalFieldManager listManager; 

    /** 
    * 
    */ 
    public ListScreen() { 
     super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT 
       | USE_ALL_WIDTH); 
     // TODO Auto-generated constructor stub 

     this.application = UiApplication.getUiApplication(); 

     LabelField screenHeading = new LabelField("Category", 
       FIELD_HCENTER) { 
      protected void paint(net.rim.device.api.ui.Graphics g) { 
       g.setColor(Color.WHITE); 
       super.paint(g); 
      } 
     }; 
     final VerticalFieldManager labelMngr = new VerticalFieldManager(USE_ALL_WIDTH); 
     labelMngr.setBackground(BackgroundFactory 
       .createBitmapBackground(LangValue.labelbg)); 
     labelMngr.add(screenHeading); 
     labelMngr.setPadding(5, 0, 5, 0); 
     add(labelMngr); 

     try { 

      listManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL 
        | Manager.VERTICAL_SCROLLBAR) { 

       protected void sublayout(int maxWidth, int maxHeight) { 
        int width = Display.getWidth(); 
        int height = Display.getHeight() 
          - labelMngr.getHeight(); 

        super.sublayout(width, height); 
        setExtent(width, height); 
       } 
      }; 

      listManager.setPadding(5, 0, 5, 0); 

      int i=0; 
      RichTextField rtf; 
      Background background = BackgroundFactory 
        .createSolidBackground(Color.WHITE); 
      Border border = BorderFactory.createSimpleBorder(new XYEdges(0, 0, 
        2, 0)); 

      CategoryHelper categoryHelper = new CategoryHelper(); 
      final String[][] cetegoryList = categoryHelper.getCategoryList(); 
      for(; i < cetegoryList.length ; i++) { 

       rtf = new RichTextField(cetegoryList[i][1], Field.FOCUSABLE) { 
        protected boolean navigationClick(int status, int time) { 

         fieldChangeNotify(1); 

         return true; 
        } 

        protected boolean touchEvent(
          net.rim.device.api.ui.TouchEvent message) { 
         if (TouchEvent.CLICK == message.getEvent()) { 
          FieldChangeListener listener = getChangeListener(); 
          if (null != listener) 
           listener.fieldChanged(this, 1); 
         } 
         return super.touchEvent(message); 
        } 

       }; 
       rtf.setBackground(Field.VISUAL_STATE_NORMAL, background); 
       rtf.setBorder(border); 
       rtf.setPadding(1, 2, 1, 3); 
       rtf.setCookie(new Category(Integer.parseInt(cetegoryList[i][0]),cetegoryList[i][1])); 
       rtf.setChangeListener(new FieldChangeListener() { 
        public void fieldChanged(Field field, int context) { 
         // Dialog.alert("play the video"); 
         // System.out.print("play the video"); 
         // code for play video 
        } 
       }); 
       listManager.add(rtf); 
      } 
      if (i == 0) { 
       listManager.add(new RichTextField("No word found.")); 
      } 

      add(listManager); 

     } catch (Exception e) { 
      System.out.println(e.getMessage()); 
      e.printStackTrace(); 
     } 
    }  

}

它工作正常進行仿真。我可以滾動列表,並可以通過滾動和關注的項目獲得藍色標記來設置任何項目的焦點。但是,當我測試BB設備時,該項目是專注的,但聚焦狀態不可見並且顏色不變,這意味着用戶無法識別哪個焦點。我的代碼中有什麼問題?

+0

可能是OS版本的問題 – tipycalFlow 2012-04-05 04:52:31

回答

2

我在RichTextField的匿名類中添加了以下代碼。

protected void onFocus(int direction){ 
     super.onFocus(direction); 
     this.setBackground(BackgroundFactory.createSolidBackground(0x001865D6)); 
     invalidate(); 
    } 

    protected void onUnfocus(){ 
     super.onUnfocus(); 
     this.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE)); 
     invalidate(); 
    }