无法解析构造函数ArrayAdapter [英] Cant resolve constructor ArrayAdapter
本文介绍了无法解析构造函数ArrayAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不能在自定义对话框中使用ArrayAdapter.
Can't use ArrayAdapter in a custom dialog.
推荐答案
您会收到此错误,因为ArrayAdapter
构造函数要求第一个参数是Context
对象.由于您是从OnClickListener
内部调用构造函数的,因此this
是指侦听器,而不是您的活动(即不是Context
).
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
).
您可以使用外部类的名称来限定this
关键字.假设代码是在MainActivity
内部编写的,则可以编写MainActivity.this
.
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.
这篇关于无法解析构造函数ArrayAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文