2011-11-18 3 views
1

ListField를 만들고 있습니다. 각 줄마다 이미지와 레이블을 추가하고 있습니다. 아무에게도 이것에 대한 keywordfilterField를 만드는 방법을 알려줄 수 있습니까? 미리 감사드립니다. 나는 블랙 베리를 처음 사용했습니다. 작정 나에게 도움이 될 것입니다 리틀 코드는이 KeywordFilterField의 문제는 내부적으로 자신의 ListField를 사용하는 사용자 지정 목록키워드 ListField for Blackberry 검색

class CustomListField extends ListField implements ListFieldCallback 
{ 
String type; 
int DISPLAY_WIDTH = Display.getWidth(); 
int DISPLAY_HEIGHT = Display.getHeight(); 
Vector mItems = new Vector(); 
Vector mine = new Vector(); 
Vector three= new Vector();  
// SizedVFM mListManager = new SizedVFM(DISPLAY_WIDTH, DISPLAY_HEIGHT - 40); 
Bitmap searchresult = Bitmap.getBitmapResource("res/searchresult.png"); 
HorizontalFieldManager hfManager; 
Bitmap image ,image1; 
int z = this.getRowHeight(); 
CustomListField(String text1,String text2,String type) 
{ 
    for (int i = 1; i < 31; i++) 
    {  
     mItems.addElement(text1 +String.valueOf(i)); 
     mine.addElement(" "+text2); 
     three.addElement("31"); 
    } 
    this.type=type; 
    this.setRowHeight((2*z));  
    this.setCallback(this); 
    this.setSize(20); 
    //mListManager.add(mListField); 
    //add(mListManager);   
} 
public void drawListRow(ListField field, Graphics g, int i, int y, int w) 
{ 
    // Draw the text. 
    image = Bitmap.getBitmapResource("res/searchresult.png"); 
    String text = (String) get(field, i); 
    String mytext = (String)mine.elementAt(i); 
    String urtext=(String)three.elementAt(i); 
    g.drawBitmap(0, y, image.getWidth(),image.getHeight(), image, 0, 0); 
    g.drawText(text, image.getWidth(), y, 0, w); 
    g.setColor(Color.GRAY); 
    g.drawText(mytext, image.getWidth(), y+getFont().getHeight(), 0, w); 
    g.drawText(urtext,Graphics.getScreenWidth()*7/8,y,0,w); 
    if (i != 0) 
    { 
      g.drawLine(0, y, w, y); 
    }  
} 

public Object get(ListField listField, int index) 
{ 
    return mItems.elementAt(index); 
} 

public int getPreferredWidth(ListField listField) 
{ 
    return DISPLAY_WIDTH; 
} 

public int indexOfList(ListField listField, String prefix, int start) 
{ 
    return 0; 
} 
protected boolean touchEvent(TouchEvent message) 
{ 
    // If click, process Field changed 
    if (message.getEvent() == TouchEvent.CLICK) 
    { 
     if(type.equals("Stops")) 
      UiApplication.getUiApplication().pushScreen(new SearchScreen("Services")); 
     else if(type.equals("Services")) 
      UiApplication.getUiApplication().pushScreen(new SearchScreen("Stops")); 
     return true; 
    } 
    return super.touchEvent(message); 
} 
} 
+0

KeywordFilterField와 함께 CustomListField를 사용할 수 있습니까? –

답변

1

를 만드는 내 코드입니다, 그래서 그것을 사용자 정의하기 어려울 거라고 생각 . 당신이 제공됩니다로 사용하고자하는 경우 다음과 같이 당신이 그것을 사용해야합니다 :

//KeywordFilterField contains a ListField to display and a search edit field to type in the words 
    KeywordFilterField keywordFilterField = new KeywordFilterField(); 

    //Instantiate the sorted collection: 
    CustomList cl = new CustomList(mItems); 

    //Pass the custom collection 
    keywordFilterField.setSourceList(cl, cl); 


    //Now you have to add two fields: first the list itself 
    myManager.add(keywordFilterField); 
    //And the search field, probably you'd want it at top: 
    myScreen.setTitle(keywordFilterField.getKeywordField()); 

당신은 디스플레이에 wan't 항목을 유지하기 위해 사용자 정의 정렬 모음을 구현해야합니다 :

class CustomList extends SortedReadableList implements KeywordProvider { 
     //In constructor, call super constructor with a comparator of <yourClass> 
     public CustomList(Vector elements) 
     { 
      super(new <yourClass>Comparator()); //pass comparator to sort 
      loadFrom(elements.elements());  
     } 

     //Interface implementation 
     public String[] getKeywords(Object element) 
     {   
      if(element instanceof <yourClass>) 
      {    
       return StringUtilities.stringToWords(element.toString()); 
      }   
      return null; 
     } 

     void addElement(Object element) 
     { 
      doAdd(element);   
     } 

     //... 
    } 

JDE 샘플 폴더에는 전체 데모가 있습니다. keywordfilterdemo라고합니다.

게시 한 것과 같은 맞춤 목록을 사용하려면 입력 된 모든 문자에 이벤트를 수신하는 키워드를 입력하는 맞춤 EditField와 같은 코드를 많이 작성해야하며 분류 된 collection (아마도 SortedReadableList을 사용할 수 있습니다.) ListField에서이 컬렉션에서 반환 한 첫 번째 검색 결과를 선택합니다.