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
Developer
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!


 

www.jackdevora.com
Developer
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..

www.jackdevora.com
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:

 

nameOfAutoCompleteFieldControl.getEditField().getText();

 

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).

 

Cheers,

 

David

Highlighted
Developer
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();
filterList.addDataSet(uniqueID,strNames,"days",BasicFilteredList.COMPARISON_IGNORE_CASE);

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
                         }
                     }
}

 

 

Contributor
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
http://www.metova.com
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.