Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 62
Registered: ‎05-30-2011
My Device: 9200
My Carrier: Etisalat
Accepted Solution

Need Help about KeywordFilterField and SortedReadableList

I have a SortedReadableList filled from a verctor and a KeywordFilterField to write in it so it filters the results and set them back to my SortedReadableList.

 

the SortedReadableList shows the elements in the from the verctor correctly but when I write some thing in the KeywordFilterField it shows always the first rows of the list according to the result but not the right result.

 

I hope you understand what I mean, So please any one can help on this

 

here is the code

 

mySortedReadableList

= new MySortedReadableList (_cities);

 

_keywordFilterField = newKeywordFilterField();

 

_keywordFilterField.setCallback(newListFieldCallback() {

 

publicvoid drawListRow(ListField list, Graphics g, int index, int y, intwidth) {

 

try{

System.

out.println("# # # # # "+ index);

 

// TODO Auto-generated method stub

String displayName = (String)

_cities.elementAt(index);

g.drawText(displayName, 0, y);

}

catch(Exception e) {

 

// TODO: handle exception

Dialog.alert(e.getMessage());

}

}

public Object get(ListField listField, intindex) {

 

if (index >= 0 && index < _cities.size()) {

 

return_keywordFilterField.getResultList().getAt(index);

}

returnnull;

}

publicintgetPreferredWidth(ListField listField) {

 

return Display.getWidth();

}

publicintindexOfList(ListField listField, String prefix,

 

intstart) {

 

returnlistField.indexOfList(prefix, start);

}

});

_keywordFilterField.setSourceList(mySortedReadableList,

 

mySortedReadableList);

 

// We're providing a customized edit field for// the KeywordFilterField.

CustomKeywordField customSearchField =

newCustomKeywordField();

customSearchField.setPadding(8, 12, 8, 12);

_keywordFilterField.setKeywordField(customSearchField);

 

// Add our KeywordFilterField to the screen and push the screen// onto the stack.

add(

_keywordFilterField.getKeywordField());

add(

_keywordFilterField);

 

 

 

 

 

class

MySortedReadableList extends SortedReadableList implementsKeywordProvider {

 

publicMySortedReadableList (Vector box1) {

 

super(newMySortedReadableListComparator());

loadFrom(box1.elements());

}

voidaddElement(Object element) {

doAdd(element);

}

publicString[] getKeywords(Object element) {

 

if (element instanceofString) {

 

return StringUtilities.stringToWords(element.toString());

}

returnnull;

}

finalstaticclass MySortedReadableListComparator implementsComparator {

 

publicintcompare(Object o1, Object o2) {

 

if (o1 == null || o2 == null) {

 

thrownewIllegalArgumentException(

 

"Cannot compare null contacts");

}

returno1.toString().compareTo(o2.toString());

}

}

 

}

 

 

 

/**

* Inner Class: A custom keyword input field for the KeywordFilterField. We

* want to prevent a save dialog from being presented to the user when

* exiting the application as the ability to persist data is not relevent to

* this application. We are also using the paint() method to customize the

* appearance of the cursor in the input field.

*/

final

class CustomKeywordField extendsBasicEditField {

 

// Contructor

CustomKeywordField() {

// Custom style.super(USE_ALL_WIDTH | NON_FOCUSABLE | NO_LEARNING | NO_NEWLINE);

 

setLabel(

"Search: ");

setFont(getFont());

}

/**

* Intercepts ESCAPE key.

*

*

@seenet.rim.device.api.ui.component.TextField#keyChar(char,int,int)

*/

protectedboolean keyChar(char ch, int status, inttime) {

 

switch(ch) {

 

case Characters.ESCAPE:

 

// Clear keyword.if (super.getTextLength() > 0) {

setText(

"");

 

returntrue;

}

}

returnsuper.keyChar(ch, status, time);

}

/**

* Overriding super to add custom painting to our class.

*

*

@seenet.rim.device.api.ui.Field#paint(Graphics)

*/

protectedvoidpaint(Graphics graphics) {

graphics.setColor(Color.

BLUEVIOLET);

graphics.setFont(getFont());

super.paint(graphics);

 

// Draw caret.

getFocusRect(

newXYRect());

drawFocus(graphics,

true);

}

}

Developer
Posts: 62
Registered: ‎05-30-2011
My Device: 9200
My Carrier: Etisalat

Re: Need Help about KeywordFilterField and SortedReadableList

Any help here??
Developer
Posts: 62
Registered: ‎05-30-2011
My Device: 9200
My Carrier: Etisalat

Re: Need Help about KeywordFilterField and SortedReadableList

Anyone can help please its and urgent case