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
Contributor
Posts: 23
Registered: ‎08-09-2010
My Device: 9800

AutoCompleteField text filtering in Blackberry

[ Edited ]

have used AutoCompleteField in blackberry and filtering the text using BasicFilteredList. It works fine in blackberry SDK 5.0 and above. But, the search is working according to the work typed. If i have an text string as below.

 

T 115 Centro Galleria Shopping Centre, Cnr Old Collier and Walters Road Morley WA 1522

 

It filters the string only if i type 152 but it cant filter if i use 522. I want it should filter as per my requirements as they are present in the above search string. Please help me to fix this issue.

 

Below is the code sample for creating AutoCompleteField

 

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.AutoCompleteField;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.text.TextFilter;
import net.rim.device.api.util.CharacterUtilities;
import net.rim.device.api.collection.util.*;

public class AutoCompleteFieldApp extends UiApplication {
	public static void main(String[] args) {
		AutoCompleteFieldApp app = new AutoCompleteFieldApp();
		app.enterEventDispatcher();
	}

	AutoCompleteFieldApp() {
		pushScreen(new HomeScreen());
	}
}

class HomeScreen extends MainScreen {
	
	LabelField selectedText;
	
	
	
	public HomeScreen() {
		setTitle("Autocomplete Text Field Demo");
		
		 selectedText = new LabelField();
		  
		BasicFilteredList filterList = new BasicFilteredList();
		String[] address = { "T 115 Centro Galleria Shopping Centre, Cnr Old Collier and Walters Road Morley WA 1522", 
				"1423 SEAVIEW POINT POINT COOK VIC 2674",
				"Lot 1498 Yarraman Road Wyndham Vale VIC 3795", 
				"Lot 3506 Witchmount Close Hillside VIC 4055",
				"6 Paas Place Williamstown VIC 4233", 
				"Lot 99 14 James Close Sunbury VIC 4502", 
				"1 Charlotte Street Clayton South VIC 4779" };
		
		filterList.addDataSet(1, address, "days", BasicFilteredList.COMPARISON_IGNORE_CASE);
		AutoCompleteField autoCompleteField = new AutoCompleteField(filterList){
			public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
		         ListField _list = getListField();
		         if (_list.getSelectedIndex() > -1) {
		             if(selectedText!=null){
		            	 BasicFilteredListResult result = (BasicFilteredListResult) selection;
		            	 selectedText.setText(result._object.toString());
		             }
		         }
		     }
		};
		add(autoCompleteField);
		
		AutoCompleteField autoCompleteField2 = new AutoCompleteField(filterList){
			public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
		         ListField _list = getListField();
		         if (_list.getSelectedIndex() > -1) {
		             if(selectedText!=null){
		            	 BasicFilteredListResult result = (BasicFilteredListResult) selection;
		            	 selectedText.setText(result._object.toString()); 
		             }
		         }
		     }
		};
		
		TextFilter filter = new TextFilter() {			
			public char convert(char c, int status) {
		        if (!validate(c))
		            return 0;
		        return c;
		    }
		    public boolean validate(char c) {
		        return CharacterUtilities.isDigit(c);
		    }
		};
		
		autoCompleteField2.getEditField().setFilter(filter);
		add(autoCompleteField2);
		
		add(selectedText);
		
		add(new SeparatorField());
		
	}
}

 

Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE

Re: AutoCompleteField text filtering in Blackberry

It hurts my eyes. Sorry!

 

I would say only one that you could set your own filterning algorithm into AutoCompleteField by BasicFilteredList where you should provide your own getKeywords implementation. I didn't find any reference that you could change defaut search (you have only option to ignore case of letters).

Contributor
Posts: 23
Registered: ‎08-09-2010
My Device: 9800

Re: AutoCompleteField text filtering in Blackberry

Hey Eugen, Nice to see your quick reply.

 

As you gave solution for writting our own algorithm with getKeywords implementation, can you please elabrate little more. I cant really understand from such highlevel.

 

Thank you.

 

Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE

Re: AutoCompleteField text filtering in Blackberry

I didn't try this, but I'm assuming this should work. First override getMatchedKeywords in your BasicFilteredList. You should return keywords that will trigger matching. So for your case "1522" you should return {"1522", "522", "22", "2"}. The object from BasicFilteredListResult should be your "1522". As you see if you have several words in searchable sentence it going to be more painful to generate all these substrings. But this is limitations of the API I think.

 

Probably there is another solution.