为什么构造函数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);