构造函数ArrayAdapter <string>未定义</string>

时间:2012-08-29 07:10:57

标签: android undefined android-arrayadapter

我有一个方法initializeViews,它在最后一行遇到 ArrayAdapter constructor undefined错误

该方法位于F1Fragment,其范围为MainFragment。然后将MainFragment附加到Activity

我们不能在Fragment构造函数中提供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);
}

1 个答案:

答案 0 :(得分:39)

F1Fragment.this更改为getActivity()Fragment不是Context