Cant resolve constructor ArrayAdapter

后端 未结 2 487
再見小時候
再見小時候 2020-12-21 11:50

Can\'t use ArrayAdapter in a custom dialog.

This is the error I am getting

相关标签:
2条回答
  • 2020-12-21 12:06

    You're getting that error because the ArrayAdapter constructor requires the first argument to be a Context object. Since you're calling the constructor from inside an OnClickListener, this refers to the listener, not your activity (i.e. not a Context).

    You can qualify the this keyword with the name of your outer class. Assuming that code is written inside of MainActivity, you could write MainActivity.this instead.

    0 讨论(0)
  • 2020-12-21 12:32

    Using this won't work since you are in the scope of the OnClickListener.

    You should try getContext() or getApplicationContext() instead of this.

    0 讨论(0)
提交回复
热议问题