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
Regular Contributor
Posts: 61
Registered: ‎02-24-2010
My Device: Storm 2
My Carrier: AT&T

Searching ListField ??

Hi..

 

 

I am implementing listfield.. I want to search the elements of listfield and show the filtered elements..

 

I don't want to use Keywordfilterfield, if possible because i have implemented everything using listfield..

 

Please suggest something..

 

Thanks

Developer
Posts: 85
Registered: ‎05-03-2010
My Device: Not Specified

Re: Searching ListField ??

Hi bb_develop;

In my humble opinion, I think you'll have to resort to searching and filtering the elements of the actual Vector or Array you used to populate the ListField and then repopulate the ListField with the new filtered elements.

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: Searching ListField ??

Can you give some sample regarding it?
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Searching ListField ??

We are recovering old ground here aren't we?

http://supportforums.blackberry.com/t5/Java-Development/TextField-and-LisdtField-on-Screen/m-p/17375...

 

As I noted in that Thread, there is nothing magic in this process, it is exactly as suggested above, you

a) take the input 'string' and

b) search your Vector of possible entries for the ListField, and

c) display only those that match.

 

Sample code will be of limited value because it almost certainly won't apply in your circumstance.  So give this process a try yourself and ask for help for the parts you can't do.  Which of (a), (b) or (c) do you have problems with?

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: Searching ListField ??

Which inputfield should be used? to which event vector elements sould be searched?
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Searching ListField ??

"Which inputfield should be used?"

 

Doesn't matter does it?

 

"to which event vector elements sould be searched? "

 

Possibly the easiest event would be to override keyChar and process the ENTER event.  Alternatively add a ButtonField and process when this is pressed. 

 

You can override keyChar and process every time the Search is updated, but that is more difficult to implement than the above and also requires, to make the UI still responsive, running the Search off the Event Thread and being able to cancel it if the user enters another character.  If you want this functionality, do it in round 2, when you have got the Enter or Button method working. 

 

 

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: Searching ListField ??

I want search result should be displayed when i start typing words in my TextField. Which event should be used?
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Searching ListField ??

keyChar, as I mentioned above.

 

However I strongly recommend that you initially implement with just ENTER functionality to start with.  It appears that you are not familiar with concepts like Threading and the BlackBerry Event model, so attempting to do it off keyChar before doing it off a button or ENTER key is like trying to run before you can walk. 

Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: Searching ListField ??

[ Edited ]

How to get compared value in a vector?

Following code i am using: 

final static class RegionComparator implements Comparator
{
public int compare(Object obj1, Object obj2) {
if (! (obj1 instanceof RegionItem && obj2 instanceof RegionItem))
throw new IllegalArgumentException("Cannot compare RegionItem");
RegionItem item1 = (RegionItem) obj1;
RegionItem item2 = (RegionItem) obj2;
return  item1.toString().compareTo(item2.toString());;
}
}

 

final Vector searchVector=new Vector();
searchVector.addElement(searchItem);

 

public String[] getKeywords( Object element )
{
if(element instanceof RegionItem)
{
RegionItem item=(RegionItem)element;
searchItem=new String[]{item.getStrSubRegionName().toString()};
return searchItem;
}
else
return null;
}

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Searching ListField ??

You can compare Objects any way you want.  Personally in this case I woud not abstract the Objects in the way you have done, In my compare routine I would already know what type of Object they were and which attribute I wanted to compare, and as a result I can do the comparison using String compare or arithmetic compare for numerical attributes.

 

This is just standard Java that you will write according to how you decide is the best way to implement your requirement.  There is not one right way.