开发者

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

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开发者_JAVA技巧 text selected by user and do something...
         }
     }
};


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


  /*  
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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜