错误:找不到适合ArrayAdapter的构造函数(DashboardFragment,int,int,String [])

时间:2016-03-05 11:58:46

标签: android

子片段如何

imaError:(31, 40) error: no suitable constructor found for ArrayAdapter(DashboardFragment,int,int,String[])
constructor ArrayAdapter.ArrayAdapter(Context,int,int,List<String>) is not applicable
(actual argument DashboardFragment cannot be converted to Context by method invocation conversion)
constructor ArrayAdapter.ArrayAdapter(Context,int,List<String>) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,int,String[]) is not applicable
(actual argument DashboardFragment cannot be converted to Context by method invocation conversion)
constructor ArrayAdapter.ArrayAdapter(Context,int,String[]) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int) is not applicable
(actual and formal argument lists differ in length)ge send to parent fragment imageview 

2 个答案:

答案 0 :(得分:2)

据推测,你有这样的事情:

new ArrayAdapter(this, ...);

其中thisDashboardFragment

将其替换为:

new ArrayAdapter(getActivity(), ...);

ArrayAdapter构造函数采用Context(通常为Activity),而不是Fragment。致电getActivity()上的Fragment,以获得合适的Context传递到ArrayAdapter

答案 1 :(得分:0)

ArrayAdapter adapter = new ArrayAdapter(getActivity()。getBaseContext(),android.R.layout.simple_list_item_1,android.R.id.text1,listdata);