子片段如何
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
答案 0 :(得分:2)
据推测,你有这样的事情:
new ArrayAdapter(this, ...);
其中this
是DashboardFragment
。
将其替换为:
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);