The constructor ArrayAdapter<string> is undefined

北战南征 提交于 2019-12-13 13:01:12

问题


I have a method, initializeViews, which encounters an ArrayAdapter constructor undefined error in its last line.

The method is located in F1Fragment, which extends MainFragment. MainFragment is then attached to an Activity.

Can we not give the context of a Fragment in the ArrayAdapter<string> constructor? I am new to Android. Please correct me. Thanks in advance.

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);
}

回答1:


Change F1Fragment.this to getActivity(). The Fragment is not a Context.



来源:https://stackoverflow.com/questions/12172578/the-constructor-arrayadapterstring-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!