Why The constructor ArrayAdapter(new View.OnKeyListener(){}, int, String[]) is undefined in following my coding. This coding is for fetching data from SQLite when typing word count is more than 3 character. But, it’s displaying the following error.
The constructor ArrayAdapter(new View.OnKeyListener(){}, int,
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;
}
});
You need to qualify the use of
thiswhen you want to refer to the enclosing class of an inner class. In your code, if the enclosing class is your Activity subclass (let’s say it’s called MyActivity), then you would write: