2012-04-04 4 views
0

다음 코드를 사용하여 목록에 사용하고 있습니다. 목록의 항목에 RichTextField을 사용했습니다.Blackberry 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

답변

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