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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 238
Registered: ‎12-26-2010
My Device: BlackBerry Z10
My Carrier: Telus

Get value of AutoCompleteField

[ Edited ]

Hi, All

I have an AutoCompleteField that is binded to a Contact datasource.

I am trying to get the value (phone number) of the selected item

when the user click a Button.

Can anyone guide me please?

Thanks in advance!


Posts: 238
Registered: ‎12-26-2010
My Device: BlackBerry Z10
My Carrier: Telus

Re: Get value of AutoCompleteField

Id really appreciate any help at all..

New Developer
Posts: 10
Registered: ‎12-15-2010
My Device: blackberry bold
My Carrier: s/w developer

Re: Get value of AutoCompleteField

facing same problem   anyone  can help  me.

New Contributor
Posts: 5
Registered: ‎01-21-2011
My Device: Curve 9330
My Carrier: Sprint

Re: Get value of AutoCompleteField

Not sure if you all got this yet, but in case anyone else needs it you should be able to get the selected value this way:




There's also a "setText()" method allowing you set the text of the control (I use that method with a "clear" button to allow the user to clear the fields, kind of like a reset).





Posts: 37
Registered: ‎10-20-2010
My Device: 9550
My Carrier: VZW

Re: Get value of AutoCompleteField

Yup, it should be getEditField.getText();  


For example:

String[] strNames = ...array values;
int uniqueID = 0;

BasicFilteredList filterList = new BasicFilteredList();

AutoCompleteField autoCompleteField = new AutoCompleteField(filterList)
		     public void onSelect(Object selection, int type) 
		         super.onSelect(selection, type);
		         if(selection != null)
		             String selection = getEditField().getText();
                             //do action with selction



Posts: 35
Registered: ‎10-06-2010
My Device: Bold 9650
My Carrier: Verizon

Re: Get value of AutoCompleteField

The selected object is returned in the onSelect(). The object is wrapped in a BasicFilteredListResult object, but you can still get to it.


Since you're using the device contact list as the data source, the selected object will be of type BlackBerryContact. Once you cast the object to BlackBerryContact, you can use the various methods of that class to extract data.


To extract the home phone number from a contact selected from the AutoCompleteField list, you would do something like this:


protected void onSelect( Object selection, int type ) {

        BasicFilteredListResult result = (BasicFilteredListResult) selection;
        BlackBerryContact contact = (BlackBerryContact) result._object;
        int numPhoneNumbers = contact.countValues( BlackBerryContact.TEL );
        for (int i = 0; i < numPhones; i++) {

            int phoneType = contact.getAttributes( BlackBerryContact.TEL, i );

            switch (phoneType) {
                case BlackBerryContact.ATTR_HOME: {
                   String homePhone = contact.getString( BlackBerryContact.TEL, i );



Joe Davis
Developer | Metova
New Developer
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile

Re: Get value of AutoCompleteField

Hi David,
Thank you for the answer. It helped too in my project.
I wish you can give another example about the setText() method, i'm trying to implement the clear button in my App but i'm not able to do that. Thank you again.