Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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;                       
    }              
});
like image 446
PPShein Avatar asked Oct 16 '11 03:10

PPShein


1 Answers

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);
like image 77
Ted Hopp Avatar answered Oct 13 '22 01:10

Ted Hopp