How to get selected item as String in BlackCom AutoCompleteField?

How to get the selected item as a string when using the Blackberry autocomplete field. I can get the selected index now. I override the onSelect method in the AutoCompleteField class as described in

JDE 5.0 Autocomplete Class API Reference

The code snippet below is

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...
         }
     }
};
+3
source share
2 answers

The standard implementation of AutoCompleteField # onSelect (Object, int) sets the text of the AutoCompleteField AutoCompleteFieldEditField object to the select parameter. This way you can query String this way. Here is 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.
         }
     }
};
+4
source
  /*  
onSelect

    protected void onSelect(Object selection,
                            int type)

    Parameters:
    *selection - The selected item*
    type - The method of selection. This will be one of SELECT_TRACKWHEEL_CLICK SELECT_TRACKBALL_CLICK SELECT_ENTER

*/

BasicFilteredList filterList = new BasicFilteredList();
        String[] days = {"Monday","Tuesday","Wednesday",
                         "Thursday","Friday","Saturday","Sunday"};
        filterList.addDataSet(1,days,"days",BasicFilteredList.COMPARISON_IGNORE_CASE);

        AutoCompleteField autoCompleteField = new AutoCompleteField(filterList){
            protected void onSelect(Object selection, int type) {
                BasicFilteredListResult result = (BasicFilteredListResult) selection;
                Dialog.alert("You selected: "+ result._object);
                super.onSelect(selection, type);
            }
        };
        add(autoCompleteField);
+3
source

Source: https://habr.com/ru/post/1733119/


All Articles