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 wor
I know this is ridiculously late but I usually use getActivity()
in this circumstance. So it would look like this:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.autosuggest, countries);
ed1.setAdapter(adapter);
You need to qualify the use of this
when 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:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MyActivity.this,
R.layout.autosuggest,
countries);
The constructor is not defined because this
is a reference to View.OnKeyListener
. Use YourOuterClass.this
instead.
The keyword this
points to the current instance of View.OnKeyListener
class. The constructor of ArrayAdapter takes current context as first parameter which is your outer class name i.e., View (say MyActivity).
You should use MyActivity.this
instead of this
.