【问题标题】:The constructor ArrayAdapter<string> is undefined构造函数 ArrayAdapter<string> 未定义
【发布时间】:2014-02-28 20:25:50
【问题描述】:

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

该方法位于F1Fragment,它扩展了MainFragment。然后将MainFragment 附加到Activity

我们不能在ArrayAdapter&lt;string&gt; 构造函数中给出Fragment 的上下文吗?我是安卓新手。请纠正我。提前致谢。

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

【问题讨论】:

    标签: android undefined android-arrayadapter


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-04
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多