android – 为什么构造函数ArrayAdapter(new View.OnKeyListener(){},int,String [])未定义

前端之家收集整理的这篇文章主要介绍了android – 为什么构造函数ArrayAdapter(new View.OnKeyListener(){},int,String [])未定义前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么构造函数ArrayAdapter(new View.OnKeyListener(){},int,String [])在编写时未定义.此编码用于在键入字数超过3个字符时从sqlite获取数据.但是,它显示以下错误.

The constructor ArrayAdapter(new View.OnKeyListener(){},
String[]) is undefined

ed1 = (AutoCompleteTextView)findViewById(R.id.searchWord);
ed1.setOnKeyListener(new View.OnKeyListener()
{
    Integer count = 0;
    String typeWord = "";
    public boolean onKey(View v,int keyCode,KeyEvent event)
    {                   
        if (KeyEvent.ACTION_DOWN == event.getAction()) {
            if (keyCode != 67) {
                count++;
                char c = (char)event.getUnicodeChar();
                typeWord = typeWord + c;
            }
            else {
                count--;
            }
            if (count > 2 && typeWord != "") {                                                                              
                countries = getAutosuggestWord(typeWord);
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.autosuggest,countries);
                ed1.setAdapter(adapter);                            
            }
        }                       
        return false;                       
    }              
});

解决方法

当你想引用内部类的封闭类时,你需要限定使用它.在你的代码中,如果封闭类是你的Activity子类(假设它叫做MyActivity),那么你会写:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MyActivity.this,countries);
原文链接:/android/318423.html

猜你在找的Android相关文章