我有一个方法,initializeViews,它在最后一行遇到ArrayAdapter构造函数未定义错误.
该方法位于F1Fragment中,它扩展了MainFragment.然后将MainFragment附加到Activity.
我们不能在ArrayAdapter< string>中给出片段的上下文吗?构造函数?我是Android新手.请指正.提前致谢.
private void initializeViews(RelativeLayout contentLayout) { leaguesListView = ( ListView ) contentLayout.findViewById ( R.id.leaguesListView ); progressLinear = (LinearLayout) contentLayout.findViewById ( R.id.progressLeagues ); values= new String[] { "RedBullRacing","McLaren","Lotus","ForceIndia","HRT","Ferrari" }; adapter= new ArrayAdapter<String>(F1Fragment.this,android.R.layout.simple_list_item_1,android.R.id.text1,values); }
解决方法
将F1Fragment.this更改为getActivity().片段不是上下文.