How to get the selected item as String in a Blackberry AutoCompleteField?

blackberry

Solution

The default implementation of AutoCompleteField#onSelect(Object, int) sets the text of the AutoCompleteField object's AutoCompleteFieldEditField to the select parameter. So you could query for the String that way. Here's a snippet of what I mean:

AutoCompleteField autoCompleteField = new AutoCompleteField(filterList)
{
     public void onSelect(Object selection, int type) {
         super.onSelect(selection, type);
         if(selection != null) {
             String selectionAsString = getEditField().getText();
             // Do whatever else you need to do with the String.
         }
     }
};

Problem

How to get the selected Item as string when using a Blackberry AutoComplete Field. I am able to get the selected index currently. I am Overriding the onSelect method in the AutoCompleteField class as explained at Autocomplete Class Reference API JDE 5.0 Code Snippet below - ``` AutoCompleteField autoCompleteField = new AutoCompleteField(filterList) { public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) { ListField _list = getListField(); if (_list.getSelectedIndex() > -1) { Dialog.alert("You selected: "+_list.getSelectedIndex()); // get text selected by user and do something... } } }; ```

Original source