2011-10-11 6 views
0

연락처 목록을 성공적으로 가져 왔습니다. 그러나 그 목록에 체크 박스를 추가 할 수는 없습니다. 나는 체크 박스와 그것의 작동으로부터 분리 된 프로그램을 만들었다. 연락처 목록에는 없습니다. 아무도 내가 여기에 체크 박스를 추가해야하는 곳을 말해 줄 수 있습니까? 코드는 다음과 같습니다.blackberry : 목록에 체크 박스 추가하기

public final class ContactsScreen extends MainScreen implements ListFieldCallback { 
    private ListField listField; 
    private ContactList blackBerryContactList; 
    private Vector blackBerryContacts; 

    public ContactsScreen(){ 
     CheckboxField checkBox1 = new CheckboxField(); 

     setTitle(new LabelField("Contacts", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH)); 

     listField = new ListField(); 
     listField.setCallback(this); 
     add(listField); 
     add(new RichTextField("Size" +(listField))); 
     reloadContactList(); 
    } 

    private boolean reloadContactList() { 
     try { 
      blackBerryContactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY); 
      Enumeration allContacts = blackBerryContactList.items(); 
      blackBerryContacts = enumToVector(allContacts); 
      listField.setSize(blackBerryContacts.size()); 
      return true; 
     } 
     catch(PIMException e){ 
      return false; 
     } 
    } 

    private Vector enumToVector(Enumeration contactEnum) { 
     Vector v = new Vector(); 

     if (contactEnum == null) 
      return v; 

     while (contactEnum.hasMoreElements()) { 
      v.addElement(contactEnum.nextElement()); 
     } 
     return v; 
    } 

    public void drawListRow(ListField fieldVar, Graphics graphics, int index, int y, int width){ 
     if (listField == fieldVar && index < blackBerryContacts.size()) 
     { 
      add(new RichTextField(blackBerryContacts.size())); 
      BlackBerryContact item = (BlackBerryContact)blackBerryContacts.elementAt(index); 
      String displayName = getDisplayName(item); 
      graphics.drawText(displayName, 0, y, 0, width); 
     } 
    } 

    public Object get(ListField fieldVar, int index) 
    { 
     if (listField == fieldVar) { 
      return blackBerryContacts.elementAt(index); 
     } 
     return null; 
    } 

    public int getPreferredWidth(ListField fieldVar) { 
     return Display.getWidth(); 
    } 

    public int indexOfList(ListField fieldVar, String prefix, int start) 
    { 
     return -1; // not implemented 
    } 

    public static String getDisplayName(Contact contact) { 
     if (contact == null) { 
      return null; } 

     String displayName = null; 

     // First, see if there is a meaningful name set for the contact. 
     if (contact.countValues(Contact.NAME) > 0) { 
      final String[] name = contact.getStringArray(Contact.NAME, 0); 
      final String firstName = name[Contact.NAME_GIVEN]; 
      final String lastName = name[Contact.NAME_FAMILY]; 
      if (firstName != null && lastName != null) { 
       displayName = firstName + " " + lastName; 
      } else if (firstName != null) { 
       displayName = firstName; 
      } else if (lastName != null) { 
       displayName = lastName; 
      } 
     } return displayName; 
    } 
} 

답변

1

ListField이 위해 설계되지 않았습니다. 해당 목록 항목은 Manager이 아니므로 하위 필드를 추가 할 수 없습니다. 즉 BB에서 ListField으로는이 작업을 수행 할 수 없습니다. ListField은 너무 많은 RAM을 먹지 않고 긴 목록을 UI에 표시하는 방법입니다 (이 경우 유일한 UI 개체 인 ListField이 있기 때문에).

목록이 너무 길지 않은 경우 (10-20 항목) ListField 대신 VerticalFieldManager을 사용하십시오. 목록이 길면 & &입니다. 실제로 체크 상자가 필요하면 VerticalFieldManager + 목록 페이지 매김을 사용하는 것이 좋습니다.

관련 문제