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

Custom filter in Blackberry AutoCompleteField

I have used AutoCompleteField in blackberry and filtering the text using BasicFilteredList. It works fine in blackberry SDK 5.0 and above. But it is searching according to the begning of the word. 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.Logically as 522 is available in the string it should search. 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

 

 

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());
		
	}
}

 Thanks in advance.

Please use plain text.
BlackBerry Development Advisor
naveenan
Posts: 85
Registered: ‎10-11-2011
My Device: BlackBerry 9810
My Carrier: Rogers

Re: Custom filter in Blackberry AutoCompleteField

Hi There,

 

Here is a sample code for a custom text filter.  Does this help?

 

Thanks

 

Naveen M

Please use plain text.
Contributor
nilanchalapanigrahy
Posts: 23
Registered: ‎08-09-2010
My Device: 9800
My Carrier: Airtel

Re: Custom filter in Blackberry AutoCompleteField

@Naveenan, link is missing..
Please use plain text.
BlackBerry Development Advisor
naveenan
Posts: 85
Registered: ‎10-11-2011
My Device: BlackBerry 9810
My Carrier: Rogers

Re: Custom filter in Blackberry AutoCompleteField

Hi There,

 

Sorry, here is the link with the sample code and discussions.  

 

http://supportforums.blackberry.com/t5/Java-Development/Can-anyone-point-to-a-custom-TextFilter-exam...

 

Thanks

 

Naveen M

Please use plain text.