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

Adobe AIR Development

Reply
New Developer
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

How to get "filterFunction" to sort only the beginning letter

Alright so I have a textInput and a listControl right under the textInput. When you click the textInput the listControl shows and has a list populated of every item in my arrayCollection. Once a user starts typing, the first letter gets changed to uppercase and the filterFunction filters the array to only show items that meet that criteria. For example when a user types "A" in the textInput all items in my array that have an "A" in them show. I want the filter to only show words that begin with "A". So when the user types "A" all the items that begin with "A" show. I want this to go for every letter after also. So if the user types "As" all the items in the ArrayCollection that begin with "As" Show. Can anyone give me any help with this type of filter. I put my code below if anyone could help me out it would be greatly aprieacted.

 

public var typedSmiley Frustratedtring;

import mx.collections.ArrayCollection;

 

private function typing():void{

if (ACList.visible == false){

ACList.visible = true;

}

}

private function filter(itemSmiley Surprisedbject):Boolean{

typed = AC.text.toLowerCase();

var itemNameSmiley Frustratedtring = (item as String).toLowerCase();

 

return itemName.indexOf(typed) > -1;

}

private function filterSetup():void{

elementCollection.filterFunction = filter;

elementCollection.refresh();

}

private function listClick():void{

AC.text = ACList.selectedItem.toString();searchElement();}

  searchElement();

}

Developer
Posts: 231
Registered: ‎05-03-2011
My Device: PlayBook V1 and proud of it :-)
My Carrier: Legs

Re: How to get "filterFunction" to sort only the beginning letter

Your filter method should return true or false, this states wether the item should be displayed or not, so you need to pass your filter string and do a compare ignoring case

 

if itemName == typed return true else return false, is your case though you must find out if number of characters in itemName match first characters of typed using string.slice()

 

Keep the Forum productive and useful for all. Click Kudos button if I've helped you. Select Solved to help everyone.

PlayBook qualifying app - Pandoras' Lights
Blog - CoCopia.co.uk Catch me on Twitter cocopia_apps
New Developer
Posts: 74
Registered: ‎02-09-2011
My Device: Torch 9850/64GB PlayBook
My Carrier: Verizon

Re: How to get "filterFunction" to sort only the beginning letter


Alright I think I fiqured it out, but now I get error (1176: Comparison between a value with static type Array and a possibly unrelated type String.) I think I understand this problem but Im not sure how to fix it. To me it seems like an ArrayCollection is not strings and so when I try compairing the text entered into AC.Text I get this error. How can I compair AC.Text (String) to the Array Items? Thanks in adavcne.

 

 

private function filter(itemSmiley Surprisedbject):Boolean{

 

typed = AC.text.toLowerCase();

var itemNameSmiley Frustratedtring = (item as String).toLowerCase();

 

if (itemName.split(0, (typed.length)) == typed){

return true;

}

else{

return false;

}

}


 

Highlighted
Developer
Posts: 231
Registered: ‎05-03-2011
My Device: PlayBook V1 and proud of it :-)
My Carrier: Legs

Re: How to get "filterFunction" to sort only the beginning letter

Not sure about this but add .tostring() to the end of this line

typed = AC.text.toLowerCase().tostring();

 

or if my syntax is right you can cast it to a string

 

typed = string(AC.text.toLowerCase()); Smiley Happy and thanks for the kudos

 

Keep the Forum productive and useful for all. Click Kudos button if I've helped you. Select Solved to help everyone.

PlayBook qualifying app - Pandoras' Lights
Blog - CoCopia.co.uk Catch me on Twitter cocopia_apps