Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java BlackBerry-如何在KeywordFilterField中附加和获取特定字段id_Java_Blackberry_Blackberry Simulator_Blackberry Eclipse Plugin_Blackberry Jde - Fatal编程技术网

Java BlackBerry-如何在KeywordFilterField中附加和获取特定字段id

Java BlackBerry-如何在KeywordFilterField中附加和获取特定字段id,java,blackberry,blackberry-simulator,blackberry-eclipse-plugin,blackberry-jde,Java,Blackberry,Blackberry Simulator,Blackberry Eclipse Plugin,Blackberry Jde,我已经设置了一个关键字过滤器字段(感谢Signare-),一切正常,但是,我想知道如何让他们做一些事情,或者在按下/单击时打开一个新屏幕。有人(也是Signare)建议我将字段id附加到焦点字段,然后在单击时使用该值打开新屏幕,但我不知道如何实现这一点 下面是我的代码: public class IndexScreen extends MainScreen { KeywordFilterField _keywordFilterField; CountryList _countr

我已经设置了一个关键字过滤器字段(感谢Signare-),一切正常,但是,我想知道如何让他们做一些事情,或者在按下/单击时打开一个新屏幕。有人(也是Signare)建议我将字段id附加到焦点字段,然后在单击时使用该值打开新屏幕,但我不知道如何实现这一点

下面是我的代码:

public class IndexScreen extends MainScreen {

    KeywordFilterField _keywordFilterField;
    CountryList _countryList;

    public IndexScreen() {
        _countryList = new CountryList();
        _countryList.addElement(new Country("Zimbabwe"));
        _countryList.addElement(new Country("Argentina"));
        _countryList.addElement(new Country("Brazil"));
        _countryList.addElement(new Country("Canada"));
        _countryList.addElement(new Country("Chile"));
        _countryList.addElement(new Country("China"));
        _countryList.addElement(new Country("Germany"));

        _keywordFilterField = new KeywordFilterField();
        _keywordFilterField.setLabel("");
        _keywordFilterField.setSourceList(_countryList, _countryList);

        setTitle(_keywordFilterField.getKeywordField());
        add(_keywordFilterField);
        // this.addMenuItem(addElementItem);

        // add(this);
    }

    void addElementToList(Country country) {
        _countryList.addElement(country);
        _keywordFilterField.updateList();
    }

    private final MenuItem addElementItem = new MenuItem("Add country", 0, 0) {
        public void run() {
            _keywordFilterField.setKeyword("");

            String[] selections = { "Add", "Cancel" };
            Dialog addDialog = new Dialog("Add Country", selections, null, 0,
                    null);
            EditField inputField = new EditField("Country: ", "");
            addDialog.add(inputField);

            if (addDialog.doModal() == 0) {
                addElementToList(new Country(inputField.getText()));
            }
        }
    };
}

class SearchFieldDemoScreen extends MainScreen {
    public SearchFieldDemoScreen() {
    };
}

class CountryList extends SortedReadableList implements KeywordProvider {
    public CountryList() {
        super(new CountryListComparator());
    }

    void addElement(Object element) {
        doAdd(element);
    }

    public String[] getKeywords(Object element) {
        if (element instanceof Country) {
            return StringUtilities.stringToWords(element.toString());
        }
        return null;
    }

    final static class CountryListComparator implements Comparator {
        public int compare(Object o1, Object o2) {
            if (o1 == null || o2 == null)
                throw new IllegalArgumentException(
                        "Cannot compare null countries");

            return o1.toString().compareTo(o2.toString());
        }
    }

}

class Country {
    private String _countryName;

    public Country(String countryName) {
        _countryName = countryName;
    }

    public String toString() {
        return _countryName;
    }

    protected boolean navigationClick(int status, int time) {

        Field f = getFieldWithFocus();
        {
            return true;
        }
    }

    private Field getFieldWithFocus() {
        // TODO Auto-generated method stub
        return null;
    }

}

请提供帮助。

这将显示单击的国家名称

public final class MyScreen extends MainScreen
{
    KeywordFilterField _keywordFilterField;  
    CountryList _countryList;
public MyScreen(){
 _countryList = new CountryList();
        _countryList.addElement(new Country("Zimbabwe"));
        _countryList.addElement(new Country("Argentina"));
        _countryList.addElement(new Country("Brazil"));
        _countryList.addElement(new Country("Canada"));
        _countryList.addElement(new Country("Chile"));
        _countryList.addElement(new Country("China"));
        _countryList.addElement(new Country("Germany"));

        _keywordFilterField = new KeywordFilterField(){
             protected boolean navigationClick(int status, int time) {
                 int index = getSelectedIndex();

                 String str = (((Country) getElementAt(index)).toString());
                 Dialog.alert(str);

                return true;
             }
        };
        _keywordFilterField.setLabel("");
        _keywordFilterField.setSourceList(_countryList, _countryList);
        add(_keywordFilterField);

}

}

class CountryList extends SortedReadableList implements KeywordProvider
{
    public CountryList()
    {
        super(new CountryListComparator());      
    }

    void addElement(Object element)
    {
        doAdd(element);      
    }

    public String[] getKeywords(Object element)
    {
        if(element instanceof Country)
        {
            return StringUtilities.stringToWords(element.toString());
        }
        return null;
    }

    final static class CountryListComparator implements Comparator
    {
        public int compare(Object o1, Object o2)
        {
            if (o1 == null || o2 == null)
                throw new IllegalArgumentException("Cannot compare null countries");

            return o1.toString().compareTo(o2.toString());
        }
    }

}

class Country
{
    private String _countryName;

    public Country(String countryName)
    {
        _countryName = countryName;      
    }

    public String toString()
    {
        return _countryName;
    }

}

你能用同样的方法更新你的博客文章来纠正代码吗?