无法解析构造函数ArrayAdapter [英] Cant resolve constructor ArrayAdapter

查看:737
本文介绍了无法解析构造函数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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆